summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Laxalde <denis@laxalde.org>2019-09-28 15:52:25 +0200
committerPatrick Steinhardt <ps@pks.im>2020-03-26 16:20:18 +0100
commit85ab27c8108015368a1597dde484ae85ed4b06c9 (patch)
treeb1857e4aec6225917ed81e4754851a72026b9545
parent3c605da6e7a5aabde3d1929494347a8b8b3f4f51 (diff)
downloadlibgit2-85ab27c8108015368a1597dde484ae85ed4b06c9.tar.gz
patch_parse: handle patches with new empty files
Patches containing additions of empty files will not contain diff data but will end with the index header line followed by the terminating sequence "-- ". We follow the same logic as in cc4c44a and allow "-- " to immediately follow the index header.
-rw-r--r--src/patch_parse.c1
-rw-r--r--tests/diff/parse.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index b649a1c09..87bc311c5 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -394,6 +394,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 a067861de..7d9f4b2e5 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);