@@ -99,6 +99,9 @@ fn patch(input: Input<'_>) -> IResult<Input<'_>, Patch> {
99
99
if let Ok ( patch) = binary_files_differ ( input) {
100
100
return Ok ( patch) ;
101
101
}
102
+ if let Ok ( patch) = file_rename_only ( input) {
103
+ return Ok ( patch) ;
104
+ }
102
105
let ( input, files) = headers ( input) ?;
103
106
let ( input, hunks) = chunks ( input) ?;
104
107
let ( input, no_newline_indicator) = no_newline_indicator ( input) ?;
@@ -151,6 +154,36 @@ fn binary_files_differ(input: Input<'_>) -> IResult<Input<'_>, Patch> {
151
154
) )
152
155
}
153
156
157
+ /// Parse patches with "similarity index 100%", i.e., patches where a file is renamed without any
158
+ /// other change in its diff.
159
+ ///
160
+ /// The `parse` function should handle rename diffs with similary index less than 100%, at least as per the test
161
+ /// `parses_file_renames_with_some_diff`.
162
+ fn file_rename_only ( input : Input < ' _ > ) -> IResult < Input < ' _ > , Patch > {
163
+ let ( rest, _parsed) = take_until ( "\n similarity index 100%\n " ) ( input) ?;
164
+ let ( rest, _parsed) = tag ( "\n similarity index 100%\n " ) ( rest) ?;
165
+
166
+ let ( rest, old_name) = delimited ( tag ( "rename from " ) , take_until ( "\n " ) , line_ending) ( rest) ?;
167
+
168
+ let ( rest, new_name) = delimited ( tag ( "rename to " ) , take_until ( "\n " ) , line_ending) ( rest) ?;
169
+
170
+ Ok ( (
171
+ rest,
172
+ Patch {
173
+ old : File {
174
+ path : Cow :: Borrowed ( & old_name) ,
175
+ meta : None ,
176
+ } ,
177
+ new : File {
178
+ path : Cow :: Borrowed ( & new_name) ,
179
+ meta : None ,
180
+ } ,
181
+ hunks : Vec :: new ( ) ,
182
+ end_newline : false ,
183
+ } ,
184
+ ) )
185
+ }
186
+
154
187
// Header lines
155
188
fn headers ( input : Input < ' _ > ) -> IResult < Input < ' _ > , ( File , File ) > {
156
189
// Ignore any preamble lines in produced diffs
0 commit comments