Skip to content

Commit cc4c44a

Browse files
committed
patch_parse: fix parsing patches only containing exact renames
Patches which contain exact renames only will not contain an actual diff body, but only a list of files that were renamed. Thus, the patch header is immediately followed by the terminating sequence "-- ". We currently do not recognize this character sequence as a possible terminating sequence. Add it and create a test to catch the failure.
1 parent 57bc9da commit cc4c44a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/patch_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ static const parse_header_transition transitions[] = {
439439
/* Next patch */
440440
{ "diff --git " , STATE_END, 0, NULL },
441441
{ "@@ -" , STATE_END, 0, NULL },
442+
{ "-- " , STATE_END, 0, NULL },
442443
};
443444

444445
static int parse_header_git(

tests/diff/parse.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ static void test_parse_invalid_diff(const char *invalid_diff)
5757
git_buf_free(&buf);
5858
}
5959

60+
void test_diff_parse__exact_rename(void)
61+
{
62+
const char *content =
63+
"---\n"
64+
" old_name.c => new_name.c | 0\n"
65+
" 1 file changed, 0 insertions(+), 0 deletions(-)\n"
66+
" rename old_name.c => new_name.c (100%)\n"
67+
"\n"
68+
"diff --git a/old_name.c b/new_name.c\n"
69+
"similarity index 100%\n"
70+
"rename from old_name.c\n"
71+
"rename to new_name.c\n"
72+
"-- \n"
73+
"2.9.3\n";
74+
git_diff *diff;
75+
76+
cl_git_pass(git_diff_from_buffer(
77+
&diff, content, strlen(content)));
78+
git_diff_free(diff);
79+
}
80+
6081
void test_diff_parse__invalid_patches_fails(void)
6182
{
6283
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);

0 commit comments

Comments
 (0)