@@ -181,6 +181,19 @@ void rugged_remote_init_callbacks_and_payload_from_options(
181
181
}
182
182
}
183
183
184
+ static int parse_prune_type (VALUE rb_prune_type )
185
+ {
186
+ if (rb_prune_type == Qtrue ) {
187
+ return GIT_FETCH_PRUNE ;
188
+ } else if (rb_prune_type == Qfalse ) {
189
+ return GIT_FETCH_NO_PRUNE ;
190
+ } else if (rb_prune_type == Qnil ) {
191
+ return GIT_FETCH_PRUNE_UNSPECIFIED ;
192
+ } else {
193
+ rb_raise (rb_eTypeError , "wrong argument type for :prune (expected true, false or nil)" );
194
+ }
195
+ }
196
+
184
197
static void rb_git_remote__free (git_remote * remote )
185
198
{
186
199
git_remote_free (remote );
@@ -502,6 +515,10 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
502
515
* :message ::
503
516
* The message to insert into the reflogs. Defaults to "fetch".
504
517
*
518
+ * :prune ::
519
+ * Specifies the prune mode for the fetch. +true+ remove any remote-tracking references that
520
+ * no longer exist, +false+ do not prune, +nil+ use configured settings Defaults to "nil".
521
+ *
505
522
* Example:
506
523
*
507
524
* remote = Rugged::Remote.lookup(@repo, 'origin')
@@ -536,6 +553,10 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
536
553
VALUE rb_val = rb_hash_aref (rb_options , CSTR2SYM ("message" ));
537
554
if (!NIL_P (rb_val ))
538
555
log_message = StringValueCStr (rb_val );
556
+
557
+ VALUE rb_prune_type = rb_hash_aref (rb_options , CSTR2SYM ("prune" ));
558
+ if (!NIL_P (rb_prune_type ))
559
+ opts .prune = parse_prune_type (rb_prune_type );
539
560
}
540
561
541
562
error = git_remote_fetch (remote , & refspecs , & opts , log_message );
@@ -620,6 +641,49 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
620
641
return payload .result ;
621
642
}
622
643
644
+ /*
645
+ * call-seq:
646
+ * remote.prune(options = {}) -> nil
647
+ *
648
+ * Prune tracking refs that are no longer present on remote
649
+ *
650
+ * Returns nil
651
+ *
652
+ * The following options can be passed in the +options+ Hash:
653
+ *
654
+ * :credentials ::
655
+ * The credentials to use for the fetch operation. Can be either an instance of one
656
+ * of the Rugged::Credentials types, or a proc returning one of the former.
657
+ * The proc will be called with the +url+, the +username+ from the url (if applicable) and
658
+ * a list of applicable credential types.
659
+ *
660
+ * Example:
661
+ *
662
+ * remote = Rugged::Remote.lookup(@repo, 'origin')
663
+ * remote.prune()
664
+ *
665
+ */
666
+ static VALUE rb_git_remote_prune (int argc , VALUE * argv , VALUE self )
667
+ {
668
+ VALUE rb_options ;
669
+ git_remote * remote ;
670
+ git_fetch_options opts = GIT_FETCH_OPTIONS_INIT ;
671
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
672
+ int error ;
673
+
674
+ Data_Get_Struct (self , git_remote , remote );
675
+ rb_scan_args (argc , argv , ":" , & rb_options );
676
+ rugged_remote_init_callbacks_and_payload_from_options (rb_options , & opts .callbacks , & payload );
677
+
678
+ if ((error = git_remote_connect (remote , GIT_DIRECTION_FETCH , & opts .callbacks )) ||
679
+ (error = git_remote_prune (remote , & opts .callbacks )))
680
+ git_remote_disconnect (remote );
681
+
682
+ rugged_exception_check (error );
683
+
684
+ return Qnil ;
685
+ }
686
+
623
687
void Init_rugged_remote (void )
624
688
{
625
689
rb_cRuggedRemote = rb_define_class_under (rb_mRugged , "Remote" , rb_cObject );
@@ -634,4 +698,5 @@ void Init_rugged_remote(void)
634
698
rb_define_method (rb_cRuggedRemote , "check_connection" , rb_git_remote_check_connection , -1 );
635
699
rb_define_method (rb_cRuggedRemote , "fetch" , rb_git_remote_fetch , -1 );
636
700
rb_define_method (rb_cRuggedRemote , "push" , rb_git_remote_push , -1 );
701
+ rb_define_method (rb_cRuggedRemote , "prune" , rb_git_remote_prune , -1 );
637
702
}
0 commit comments