@@ -806,9 +806,6 @@ static VALUE rb_git_index_diff(VALUE self, VALUE rb_other, VALUE rb_options)
806
806
owner = rugged_owner (self );
807
807
Data_Get_Struct (owner , git_repository , repo );
808
808
809
- if (NIL_P (rb_other )) {
810
- error = git_diff_index_to_workdir (& diff , repo , index , & opts );
811
- } else {
812
809
// Need to flip the reverse option, so that the index is by default
813
810
// the "old file" side of the diff.
814
811
opts .flags ^= GIT_DIFF_REVERSE ;
@@ -829,7 +826,29 @@ static VALUE rb_git_index_diff(VALUE self, VALUE rb_other, VALUE rb_options)
829
826
xfree (opts .pathspec .strings );
830
827
rb_raise (rb_eTypeError , "A Rugged::Commit or Rugged::Tree instance is required" );
831
828
}
832
- }
829
+
830
+ xfree (opts .pathspec .strings );
831
+ rugged_exception_check (error );
832
+
833
+ return rugged_diff_new (rb_cRuggedDiff , owner , diff );
834
+ }
835
+
836
+ static VALUE rb_git_diff_index_to_workdir (VALUE self , VALUE rb_options )
837
+ {
838
+ git_index * index ;
839
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT ;
840
+ git_repository * repo ;
841
+ git_diff * diff = NULL ;
842
+ VALUE owner ;
843
+ int error ;
844
+
845
+ rugged_parse_diff_options (& opts , rb_options );
846
+
847
+ Data_Get_Struct (self , git_index , index );
848
+ owner = rugged_owner (self );
849
+ Data_Get_Struct (owner , git_repository , repo );
850
+
851
+ error = git_diff_index_to_workdir (& diff , repo , index , & opts );
833
852
834
853
xfree (opts .pathspec .strings );
835
854
rugged_exception_check (error );
@@ -1224,6 +1243,7 @@ void Init_rugged_index(void)
1224
1243
rb_define_method (rb_cRuggedIndex , "[]" , rb_git_index_get , -1 );
1225
1244
rb_define_method (rb_cRuggedIndex , "each" , rb_git_index_each , 0 );
1226
1245
rb_define_private_method (rb_cRuggedIndex , "_diff" , rb_git_index_diff , 2 );
1246
+ rb_define_private_method (rb_cRuggedIndex , "diff_index_to_workdir" , rb_git_diff_index_to_workdir , 1 );
1227
1247
1228
1248
rb_define_method (rb_cRuggedIndex , "conflicts?" , rb_git_index_conflicts_p , 0 );
1229
1249
rb_define_method (rb_cRuggedIndex , "conflicts" , rb_git_index_conflicts , 0 );
0 commit comments