@@ -829,6 +829,62 @@ static VALUE rb_git_repo_merge_analysis(int argc, VALUE *argv, VALUE self)
829
829
return result ;
830
830
}
831
831
832
+ /*
833
+ * call-seq:
834
+ * repo.revert_commit(revert_commit, our_commit, options = {}) -> index
835
+ *
836
+ * Reverts the given commit against the given "our" commit, producing an
837
+ * index that reflects the result of the revert.
838
+ */
839
+ static VALUE rb_git_repo_revert_commit (int argc , VALUE * argv , VALUE self )
840
+ {
841
+ VALUE rb_revert_commit , rb_our_commit , rb_options ;
842
+ git_commit * revert_commit , * our_commit ;
843
+ git_index * index ;
844
+ git_repository * repo ;
845
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT ;
846
+ unsigned int mainline = 0 ;
847
+ int error ;
848
+
849
+ rb_scan_args (argc , argv , "20:" , & rb_revert_commit , & rb_our_commit , & rb_options );
850
+
851
+ if (TYPE (rb_revert_commit ) == T_STRING )
852
+ rb_revert_commit = rugged_object_rev_parse (self , rb_revert_commit , 1 );
853
+
854
+ if (TYPE (rb_our_commit ) == T_STRING )
855
+ rb_our_commit = rugged_object_rev_parse (self , rb_our_commit , 1 );
856
+
857
+ if (!rb_obj_is_kind_of (rb_revert_commit , rb_cRuggedCommit ) ||
858
+ !rb_obj_is_kind_of (rb_our_commit , rb_cRuggedCommit )) {
859
+ rb_raise (rb_eArgError , "Expected a Rugged::Commit." );
860
+ }
861
+
862
+ if (!NIL_P (rb_options )) {
863
+ VALUE rb_mainline ;
864
+
865
+ Check_Type (rb_options , T_HASH );
866
+ rugged_parse_merge_options (& opts , rb_options );
867
+
868
+ rb_mainline = rb_hash_aref (rb_options , CSTR2SYM ("mainline" ));
869
+ if (!NIL_P (rb_mainline )) {
870
+ Check_Type (rb_mainline , T_FIXNUM );
871
+ mainline = FIX2UINT (rb_mainline );
872
+ }
873
+ }
874
+
875
+ Data_Get_Struct (self , git_repository , repo );
876
+ Data_Get_Struct (rb_revert_commit , git_commit , revert_commit );
877
+ Data_Get_Struct (rb_our_commit , git_commit , our_commit );
878
+
879
+ error = git_revert_commit (& index , repo , revert_commit , our_commit , mainline , & opts );
880
+ if (error == GIT_EMERGECONFLICT )
881
+ return Qnil ;
882
+
883
+ rugged_exception_check (error );
884
+
885
+ return rugged_index_new (rb_cRuggedIndex , self , index );
886
+ }
887
+
832
888
/*
833
889
* call-seq:
834
890
* repo.merge_commits(our_commit, their_commit, options = {}) -> index
@@ -2528,6 +2584,8 @@ void Init_rugged_repo(void)
2528
2584
rb_define_method (rb_cRuggedRepo , "merge_analysis" , rb_git_repo_merge_analysis , -1 );
2529
2585
rb_define_method (rb_cRuggedRepo , "merge_commits" , rb_git_repo_merge_commits , -1 );
2530
2586
2587
+ rb_define_method (rb_cRuggedRepo , "revert_commit" , rb_git_repo_revert_commit , -1 );
2588
+
2531
2589
rb_define_method (rb_cRuggedRepo , "path_ignored?" , rb_git_repo_is_path_ignored , 1 );
2532
2590
2533
2591
rb_define_method (rb_cRuggedRepo , "reset" , rb_git_repo_reset , 2 );
0 commit comments