diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-04 18:04:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 18:04:01 +0100 |
commit | a94fedc11334b23e864824ef33156a660b10022d (patch) | |
tree | bb3ef88c1ccef0bb42fc0f75e22aa5789c6530fc | |
parent | a1f0135dfc9d57f88245229f40e6461f636e63b1 (diff) | |
parent | 74293ea04a21f35151f0be095baf7bd3b3fd339c (diff) | |
download | libgit2-a94fedc11334b23e864824ef33156a660b10022d.tar.gz |
Merge pull request #5620 from dlax/parse-patch-add-delete-no-index
patch_parse: handle absence of "index" header for new/deleted cases
-rw-r--r-- | src/patch_parse.c | 1 | ||||
-rw-r--r-- | tests/diff/parse.c | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c index f65b1087d..2bf94c2cb 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -407,6 +407,7 @@ static const parse_header_transition transitions[] = { { "--- " , STATE_DIFF, STATE_PATH, parse_header_git_oldpath }, { "--- " , STATE_INDEX, STATE_PATH, parse_header_git_oldpath }, + { "--- " , STATE_FILEMODE, STATE_PATH, parse_header_git_oldpath }, { "+++ " , STATE_PATH, STATE_END, parse_header_git_newpath }, { "GIT binary patch" , STATE_INDEX, STATE_END, NULL }, { "Binary files " , STATE_INDEX, STATE_END, NULL }, diff --git a/tests/diff/parse.c b/tests/diff/parse.c index 56f2253aa..6b6e6645e 100644 --- a/tests/diff/parse.c +++ b/tests/diff/parse.c @@ -107,6 +107,29 @@ void test_diff_parse__no_extended_headers(void) git_diff_free(diff); } +void test_diff_parse__add_delete_no_index(void) +{ + const char *content = + "diff --git a/file.txt b/file.txt\n" + "new file mode 100644\n" + "--- /dev/null\n" + "+++ b/file.txt\n" + "@@ -0,0 +1,2 @@\n" + "+one\n" + "+two\n" + "diff --git a/otherfile.txt b/otherfile.txt\n" + "deleted file mode 100644\n" + "--- a/otherfile.txt\n" + "+++ /dev/null\n" + "@@ -1,1 +0,0 @@\n" + "-three\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); |