Skip to content

Commit 56a2ae0

Browse files
committed
apply: test rename 2 to 1
Test that we can apply a patch that renames two different files to the same target filename. Git itself handles this scenario in a last-write wins, such that the rename listed last is the one persisted in the target. Ensure that we do the same.
1 parent 235dc9b commit 56a2ae0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tests/apply/apply_helpers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@
235235
"rename from beef.txt\n" \
236236
"rename to asparagus.txt\n"
237237

238+
#define DIFF_RENAME_2_TO_1 \
239+
"diff --git a/asparagus.txt b/2.txt\n" \
240+
"similarity index 100%\n" \
241+
"rename from asparagus.txt\n" \
242+
"rename to 2.txt\n" \
243+
"diff --git a/beef.txt b/2.txt\n" \
244+
"similarity index 100%\n" \
245+
"rename from beef.txt\n" \
246+
"rename to 2.txt\n"
247+
238248
struct iterator_compare_data {
239249
struct merge_index_entry *expected;
240250
size_t cnt;

tests/apply/both.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,27 @@ void test_apply_both__rename_circular(void)
524524

525525
git_diff_free(diff);
526526
}
527+
528+
void test_apply_both__rename_2_to_1(void)
529+
{
530+
git_diff *diff;
531+
532+
struct merge_index_entry both_expected[] = {
533+
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "2.txt" },
534+
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
535+
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
536+
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
537+
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" }
538+
};
539+
size_t both_expected_cnt = sizeof(both_expected) /
540+
sizeof(struct merge_index_entry);
541+
542+
cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_2_TO_1,
543+
strlen(DIFF_RENAME_2_TO_1)));
544+
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
545+
546+
validate_apply_index(repo, both_expected, both_expected_cnt);
547+
validate_apply_workdir(repo, both_expected, both_expected_cnt);
548+
549+
git_diff_free(diff);
550+
}

0 commit comments

Comments
 (0)