Skip to content

Commit a3c1070

Browse files
committed
apply: test modify delta after rename delta
Ensure that we can apply a delta after renaming a file.
1 parent 07e71bf commit a3c1070

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/apply/apply_helpers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,31 @@
294294
"+\n" \
295295
"+This is another change to a new file.\n"
296296

297+
#define DIFF_RENAME_AND_MODIFY_DELTAS \
298+
"diff --git a/veal.txt b/asdf.txt\n" \
299+
"similarity index 96%\n" \
300+
"rename from veal.txt\n" \
301+
"rename to asdf.txt\n" \
302+
"index 94d2c01..292cb60 100644\n" \
303+
"--- a/veal.txt\n" \
304+
"+++ b/asdf.txt\n" \
305+
"@@ -15,4 +15,4 @@ will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
306+
" in, first taking off their skins, by letting them stand a few minutes in\n" \
307+
" hot water, when they may be easily peeled. When made in this way you\n" \
308+
" must thicken it with the flour only. Any part of the veal may be used,\n" \
309+
"-but the shin or knuckle is the nicest.\n" \
310+
"+but the shin or knuckle is the nicest!\n" \
311+
"diff --git a/asdf.txt b/asdf.txt\n" \
312+
"index 292cb60..61c686b 100644\n" \
313+
"--- a/asdf.txt\n" \
314+
"+++ b/asdf.txt\n" \
315+
"@@ -1,4 +1,4 @@\n" \
316+
"-VEAL SOUP!\n" \
317+
"+VEAL SOUP\n" \
318+
"\n" \
319+
" Put into a pot three quarts of water, three onions cut small, one\n" \
320+
" spoonful of black pepper pounded, and two of salt, with two or three\n"
321+
297322
struct iterator_compare_data {
298323
struct merge_index_entry *expected;
299324
size_t cnt;

tests/apply/both.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,28 @@ void test_apply_both__two_deltas_one_new_file(void)
625625

626626
git_diff_free(diff);
627627
}
628+
629+
void test_apply_both__rename_and_modify_deltas(void)
630+
{
631+
git_diff *diff;
632+
633+
struct merge_index_entry both_expected[] = {
634+
{ 0100644, "61c686bed39684eee8a2757ceb1291004a21333f", 0, "asdf.txt" },
635+
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
636+
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
637+
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
638+
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
639+
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
640+
};
641+
size_t both_expected_cnt = sizeof(both_expected) /
642+
sizeof(struct merge_index_entry);
643+
644+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_DELTAS,
645+
strlen(DIFF_RENAME_AND_MODIFY_DELTAS)));
646+
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
647+
648+
validate_apply_index(repo, both_expected, both_expected_cnt);
649+
validate_apply_workdir(repo, both_expected, both_expected_cnt);
650+
651+
git_diff_free(diff);
652+
}

0 commit comments

Comments
 (0)