Skip to content

Commit 4e746d8

Browse files
committed
test: ensure applying a patch can't delete a file twice
1 parent f8b9493 commit 4e746d8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/apply/apply_helpers.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,40 @@
419419
"@@ -0,0 +1 @@\n" \
420420
"+New file.\n" \
421421

422+
#define DIFF_REMOVE_FILE_TWICE \
423+
"diff --git a/asparagus.txt b/asparagus.txt\n" \
424+
"deleted file mode 100644\n" \
425+
"index f516580..0000000\n" \
426+
"--- a/asparagus.txt\n" \
427+
"+++ /dev/null\n" \
428+
"@@ -1,10 +0,0 @@\n" \
429+
"-ASPARAGUS SOUP!\n" \
430+
"-\n" \
431+
"-Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
432+
"-of the tops, and lay them in water, chop the stalks and put them on the\n" \
433+
"-fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
434+
"-add two quarts of water, boil them till the stalks are quite soft, then\n" \
435+
"-pulp them through a sieve, and strain the water to it, which must be put\n" \
436+
"-back in the pot; put into it a chicken cut up, with the tops of\n" \
437+
"-asparagus which had been laid by, boil it until these last articles are\n" \
438+
"-sufficiently done, thicken with flour, butter and milk, and serve it up.\n" \
439+
"diff --git a/asparagus.txt b/asparagus.txt\n" \
440+
"deleted file mode 100644\n" \
441+
"index f516580..0000000\n" \
442+
"--- a/asparagus.txt\n" \
443+
"+++ /dev/null\n" \
444+
"@@ -1,10 +0,0 @@\n" \
445+
"-ASPARAGUS SOUP!\n" \
446+
"-\n" \
447+
"-Take four large bunches of asparagus, scrape it nicely, cut off one inch\n" \
448+
"-of the tops, and lay them in water, chop the stalks and put them on the\n" \
449+
"-fire with a piece of bacon, a large onion cut up, and pepper and salt;\n" \
450+
"-add two quarts of water, boil them till the stalks are quite soft, then\n" \
451+
"-pulp them through a sieve, and strain the water to it, which must be put\n" \
452+
"-back in the pot; put into it a chicken cut up, with the tops of\n" \
453+
"-asparagus which had been laid by, boil it until these last articles are\n" \
454+
"-sufficiently done, thicken with flour, butter and milk, and serve it up.\n"
455+
422456
struct iterator_compare_data {
423457
struct merge_index_entry *expected;
424458
size_t cnt;

tests/apply/both.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,14 @@ void test_apply_both__readd_deleted_file(void)
723723

724724
git_diff_free(diff);
725725
}
726+
727+
void test_apply_both__cant_remove_file_twice(void)
728+
{
729+
git_diff *diff;
730+
731+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_REMOVE_FILE_TWICE,
732+
strlen(DIFF_REMOVE_FILE_TWICE)));
733+
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
734+
735+
git_diff_free(diff);
736+
}

0 commit comments

Comments
 (0)