Skip to content

Commit 6716e2f

Browse files
authored
Merge pull request libgit2#5248 from dlax/parse-patch-empty-files
patch_parse: handle patches with new empty files
2 parents f04a58b + b61810b commit 6716e2f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/patch_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ static const parse_header_transition transitions[] = {
406406
/* Next patch */
407407
{ "diff --git " , STATE_END, 0, NULL },
408408
{ "@@ -" , STATE_END, 0, NULL },
409+
{ "-- " , STATE_INDEX, 0, NULL },
409410
{ "-- " , STATE_END, 0, NULL },
410411
};
411412

tests/diff/parse.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ void test_diff_parse__exact_rename(void)
7878
git_diff_free(diff);
7979
}
8080

81+
void test_diff_parse__empty_file(void)
82+
{
83+
const char *content =
84+
"---\n"
85+
" file | 0\n"
86+
" 1 file changed, 0 insertions(+), 0 deletions(-)\n"
87+
" created mode 100644 file\n"
88+
"\n"
89+
"diff --git a/file b/file\n"
90+
"new file mode 100644\n"
91+
"index 0000000..e69de29\n"
92+
"-- \n"
93+
"2.20.1\n";
94+
git_diff *diff;
95+
96+
cl_git_pass(git_diff_from_buffer(
97+
&diff, content, strlen(content)));
98+
git_diff_free(diff);
99+
}
100+
81101
void test_diff_parse__invalid_patches_fails(void)
82102
{
83103
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);

0 commit comments

Comments
 (0)