Skip to content

Commit

Permalink
patch_parse: fix parsing patches only containing exact renames
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Sep 1, 2017
1 parent 57bc9da commit cc4c44a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/patch_parse.c
Expand Up @@ -439,6 +439,7 @@ static const parse_header_transition transitions[] = {
/* Next patch */
{ "diff --git " , STATE_END, 0, NULL },
{ "@@ -" , STATE_END, 0, NULL },
{ "-- " , STATE_END, 0, NULL },
};

static int parse_header_git(
Expand Down
21 changes: 21 additions & 0 deletions tests/diff/parse.c
Expand Up @@ -57,6 +57,27 @@ static void test_parse_invalid_diff(const char *invalid_diff)
git_buf_free(&buf);
}

void test_diff_parse__exact_rename(void)
{
const char *content =
"---\n"
" old_name.c => new_name.c | 0\n"
" 1 file changed, 0 insertions(+), 0 deletions(-)\n"
" rename old_name.c => new_name.c (100%)\n"
"\n"
"diff --git a/old_name.c b/new_name.c\n"
"similarity index 100%\n"
"rename from old_name.c\n"
"rename to new_name.c\n"
"-- \n"
"2.9.3\n";
git_diff *diff;

cl_git_pass(git_diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}

void test_diff_parse__invalid_patches_fails(void)
{
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);
Expand Down

0 comments on commit cc4c44a

Please sign in to comment.