Merge pull request #5248 from dlax/parse-patch-empty-files patch_parse: handle patches with new empty files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 84953ee..51c4bb2 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -406,6 +406,7 @@ static const parse_header_transition transitions[] = {
/* Next patch */
{ "diff --git " , STATE_END, 0, NULL },
{ "@@ -" , STATE_END, 0, NULL },
+ { "-- " , STATE_INDEX, 0, NULL },
{ "-- " , STATE_END, 0, NULL },
};
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index a067861..7d9f4b2 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -78,6 +78,26 @@ void test_diff_parse__exact_rename(void)
git_diff_free(diff);
}
+void test_diff_parse__empty_file(void)
+{
+ const char *content =
+ "---\n"
+ " file | 0\n"
+ " 1 file changed, 0 insertions(+), 0 deletions(-)\n"
+ " created mode 100644 file\n"
+ "\n"
+ "diff --git a/file b/file\n"
+ "new file mode 100644\n"
+ "index 0000000..e69de29\n"
+ "-- \n"
+ "2.20.1\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);