Skip to content

Commit a94fedc

Browse files
authored
Merge pull request libgit2#5620 from dlax/parse-patch-add-delete-no-index
patch_parse: handle absence of "index" header for new/deleted cases
2 parents a1f0135 + 74293ea commit a94fedc

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/patch_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static const parse_header_transition transitions[] = {
407407

408408
{ "--- " , STATE_DIFF, STATE_PATH, parse_header_git_oldpath },
409409
{ "--- " , STATE_INDEX, STATE_PATH, parse_header_git_oldpath },
410+
{ "--- " , STATE_FILEMODE, STATE_PATH, parse_header_git_oldpath },
410411
{ "+++ " , STATE_PATH, STATE_END, parse_header_git_newpath },
411412
{ "GIT binary patch" , STATE_INDEX, STATE_END, NULL },
412413
{ "Binary files " , STATE_INDEX, STATE_END, NULL },

tests/diff/parse.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ void test_diff_parse__no_extended_headers(void)
107107
git_diff_free(diff);
108108
}
109109

110+
void test_diff_parse__add_delete_no_index(void)
111+
{
112+
const char *content =
113+
"diff --git a/file.txt b/file.txt\n"
114+
"new file mode 100644\n"
115+
"--- /dev/null\n"
116+
"+++ b/file.txt\n"
117+
"@@ -0,0 +1,2 @@\n"
118+
"+one\n"
119+
"+two\n"
120+
"diff --git a/otherfile.txt b/otherfile.txt\n"
121+
"deleted file mode 100644\n"
122+
"--- a/otherfile.txt\n"
123+
"+++ /dev/null\n"
124+
"@@ -1,1 +0,0 @@\n"
125+
"-three\n";
126+
git_diff *diff;
127+
128+
cl_git_pass(git_diff_from_buffer(
129+
&diff, content, strlen(content)));
130+
git_diff_free(diff);
131+
}
132+
110133
void test_diff_parse__invalid_patches_fails(void)
111134
{
112135
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);

0 commit comments

Comments
 (0)