Skip to content

Commit 605066e

Browse files
committed
apply: test renaming a file after modifying it
Multiple deltas can exist in a diff, and can be applied in-order. If there exists a delta that modifies a file followed by a delta that renames that file, then both will be captured. The modification delta will be applied and the resulting file will be staged with the original filename. The rename delta will be independently applied - to the original file (not the modified file from the original delta) and staged independently.
1 parent bd682f3 commit 605066e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tests/apply/apply_helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,13 @@
330330
"\n" \
331331
" Put into a pot three quarts of water, three onions cut small, one\n" \
332332
" spoonful of black pepper pounded, and two of salt, with two or three\n" \
333-
"diff --git a/veal.txt b/beef.txt\n" \
333+
"diff --git a/veal.txt b/other.txt\n" \
334334
"similarity index 96%\n" \
335335
"rename from veal.txt\n" \
336-
"rename to beef.txt\n" \
336+
"rename to other.txt\n" \
337337
"index 94d2c01..292cb60 100644\n" \
338338
"--- a/veal.txt\n" \
339-
"+++ b/beef.txt\n" \
339+
"+++ b/other.txt\n" \
340340
"@@ -15,4 +15,4 @@ will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
341341
" in, first taking off their skins, by letting them stand a few minutes in\n" \
342342
" hot water, when they may be easily peeled. When made in this way you\n" \

tests/apply/both.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,28 @@ void test_apply_both__rename_and_modify_deltas(void)
651651
git_diff_free(diff);
652652
}
653653

654-
void test_apply_both__cant_rename_after_modify(void)
654+
void test_apply_both__rename_delta_after_modify_delta(void)
655655
{
656656
git_diff *diff;
657657

658+
struct merge_index_entry both_expected[] = {
659+
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
660+
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
661+
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
662+
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
663+
{ 0100644, "292cb60ce5e25c337c5b6e12957bbbfe1be4bf49", 0, "other.txt" },
664+
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
665+
{ 0100644, "c8c120f466591bbe3b8867361d5ec3cdd9fda756", 0, "veal.txt" }
666+
};
667+
size_t both_expected_cnt = sizeof(both_expected) /
668+
sizeof(struct merge_index_entry);
669+
658670
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY,
659671
strlen(DIFF_RENAME_AFTER_MODIFY)));
660-
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
672+
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
673+
674+
validate_apply_index(repo, both_expected, both_expected_cnt);
675+
validate_apply_workdir(repo, both_expected, both_expected_cnt);
661676

662677
git_diff_free(diff);
663678
}

0 commit comments

Comments
 (0)