@@ -2530,6 +2530,61 @@ static VALUE rb_git_repo_cherrypick(int argc, VALUE *argv, VALUE self)
2530
2530
return Qnil ;
2531
2531
}
2532
2532
2533
+ /*
2534
+ * call-seq:
2535
+ * repo.cherrypick_commit(commit, our_commit, [mainline, options]) -> nil
2536
+ *
2537
+ * Cherry-pick the given commit on the given base in-memory and
2538
+ * return an index with the result.
2539
+ *
2540
+ * `commit` can be either a string containing a commit id or a
2541
+ * `Rugged::Commit` object.
2542
+ *
2543
+ * `our_commit` is the base commit, can be either a string containing
2544
+ * a commit id or a `Rugged::Commit` object.
2545
+ *
2546
+ * `mainline` when cherry-picking a merge, this is the parent number
2547
+ * (starting from 1) which should be considered the mainline.
2548
+ */
2549
+ static VALUE rb_git_repo_cherrypick_commit (int argc , VALUE * argv , VALUE self )
2550
+ {
2551
+ VALUE rb_options , rb_commit , rb_our_commit , rb_mainline ;
2552
+
2553
+ git_repository * repo ;
2554
+ git_commit * commit , * our_commit ;
2555
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT ;
2556
+ git_index * index ;
2557
+ int error , mainline ;
2558
+
2559
+ rb_scan_args (argc , argv , "21:" , & rb_commit , & rb_our_commit , & rb_mainline , & rb_options );
2560
+
2561
+ if (TYPE (rb_commit ) == T_STRING ) {
2562
+ rb_commit = rugged_object_rev_parse (self , rb_commit , 1 );
2563
+ }
2564
+ if (TYPE (rb_our_commit ) == T_STRING ) {
2565
+ rb_our_commit = rugged_object_rev_parse (self , rb_our_commit , 1 );
2566
+ }
2567
+
2568
+ if (!rb_obj_is_kind_of (rb_commit , rb_cRuggedCommit )) {
2569
+ rb_raise (rb_eArgError , "Expected a Rugged::Commit." );
2570
+ }
2571
+ if (!rb_obj_is_kind_of (rb_our_commit , rb_cRuggedCommit )) {
2572
+ rb_raise (rb_eArgError , "Expected a Rugged::Commit." );
2573
+ }
2574
+
2575
+ Data_Get_Struct (self , git_repository , repo );
2576
+ Data_Get_Struct (rb_commit , git_commit , commit );
2577
+ Data_Get_Struct (rb_our_commit , git_commit , our_commit );
2578
+
2579
+ rugged_parse_merge_options (& opts , rb_options );
2580
+
2581
+ mainline = NIL_P (rb_mainline ) ? 0 : FIX2UINT (rb_mainline );
2582
+ error = git_cherrypick_commit (& index , repo , commit , our_commit , mainline , & opts );
2583
+ rugged_exception_check (error );
2584
+
2585
+ return rugged_index_new (rb_cRuggedIndex , self , index );
2586
+ }
2587
+
2533
2588
void Init_rugged_repo (void )
2534
2589
{
2535
2590
id_call = rb_intern ("call" );
@@ -2603,6 +2658,7 @@ void Init_rugged_repo(void)
2603
2658
rb_define_method (rb_cRuggedRepo , "checkout_head" , rb_git_checkout_head , -1 );
2604
2659
2605
2660
rb_define_method (rb_cRuggedRepo , "cherrypick" , rb_git_repo_cherrypick , -1 );
2661
+ rb_define_method (rb_cRuggedRepo , "cherrypick_commit" , rb_git_repo_cherrypick_commit , -1 );
2606
2662
rb_define_method (rb_cRuggedRepo , "fetch_attributes" , rb_git_repo_attributes , -1 );
2607
2663
2608
2664
rb_cRuggedOdbObject = rb_define_class_under (rb_mRugged , "OdbObject" , rb_cObject );
0 commit comments