@@ -102,10 +102,10 @@ fn multiple_patches(input: Input) -> IResult<Input, Vec<Patch>> {
102102}
103103
104104fn patch ( input : Input ) -> IResult < Input , Patch > {
105+ let ( input, _diff_command) = diff_command ( input) ?;
105106 if let Ok ( patch) = file_rename_only ( input) {
106107 return Ok ( patch) ;
107108 }
108- let ( input, _diff_command) = diff_command ( input) ?;
109109 let ( input, _git_index) = git_index_line ( input) ?;
110110 if let Ok ( patch) = binary_files_differ ( input) {
111111 return Ok ( patch) ;
@@ -172,14 +172,13 @@ fn binary_files_differ(input: Input) -> IResult<Input, Patch> {
172172 ) )
173173}
174174
175- /// Parse patches with "similarity index 100%", i.e., patches where a file is renamed without any
176- /// other change in its diff.
175+ /// Attempt to match patches with "similarity index 100%", i.e., patches where a file is renamed
176+ /// without any other change in its diff.
177177///
178- /// The `parse` function should handle rename diffs with similary index less than 100%, at least as per the test
178+ /// The `parse` function should handle rename diffs with similarity index less than 100%, at least as per the test
179179/// `parses_file_renames_with_some_diff`.
180180fn file_rename_only ( input : Input < ' _ > ) -> IResult < Input < ' _ > , Patch < ' _ > > {
181- let ( rest, _parsed) = take_until ( "\n similarity index 100%\n " ) ( input) ?;
182- let ( rest, _parsed) = tag ( "\n similarity index 100%\n " ) ( rest) ?;
181+ let ( rest, _parsed) = tag ( "similarity index 100%\n " ) ( input) ?;
183182
184183 let ( rest, old_name) = delimited ( tag ( "rename from " ) , take_until ( "\n " ) , line_ending) ( rest) ?;
185184
@@ -815,4 +814,31 @@ mod tests {
815814
816815 Ok ( ( ) )
817816 }
817+
818+ #[ test]
819+ fn test_git_file_rename_without_changes ( ) -> ParseResult < ' static , ( ) > {
820+ let sample = "\
821+ diff --git a/tests/test-utils/Cargo.toml b/test-utils/Cargo.toml
822+ similarity index 100%
823+ rename from tests/test-utils/Cargo.toml
824+ rename to test-utils/Cargo.toml
825+ " ;
826+ let expected = Patch {
827+ old : File {
828+ path : "tests/test-utils/Cargo.toml" . into ( ) ,
829+ meta : None ,
830+ } ,
831+ new : File {
832+ path : "test-utils/Cargo.toml" . into ( ) ,
833+ meta : None ,
834+ } ,
835+ hunks : Vec :: new ( ) ,
836+ old_missing_newline : false ,
837+ new_missing_newline : false ,
838+ binary : false ,
839+ } ;
840+ test_parser ! ( patch( sample) -> expected) ;
841+ assert_eq ! ( format!( "{expected}\n " ) , sample) ;
842+ Ok ( ( ) )
843+ }
818844}
0 commit comments