merge: refactor merge tests for empty files treated as renames

Don't munge the "trivial" tests, those are specifically about the
"trivial" resolutions for git's tree merge. (For example, adding a file
in a new branch and making no changes in the HEAD branch is something
that can be handled _trivially_.)

For tests of rename functionality, put them in the trees::rename tests.
This commit is contained in:
Edward Thomson
2024-02-20 13:42:38 +00:00
parent 16688efa41
commit 6b54210595
26 changed files with 45 additions and 48 deletions

View File

@@ -350,3 +350,22 @@ void test_merge_trees_renames__cache_recomputation(void)
git_tree_free(our_tree);
git__free(data);
}
void test_merge_trees_renames__emptyfile_renames(void)
{
git_index *index;
git_merge_options *opts = NULL;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 1, "bar" },
{ 0100644, "60b12be2d2f57977ce83d8dfd32e2394ac1ba1a2", 3, "bar" },
{ 0100644, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 0, "boo" },
{ 0100644, "e50a49f9558d09d4d3bfc108363bb24c127ed263", 0, "foo" },
};
cl_git_pass(merge_trees_from_branches(&index, repo,
"emptyfile_renames", "emptyfile_renames-branch",
opts));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
}

View File

@@ -25,7 +25,7 @@ void test_merge_trees_trivial__cleanup(void)
}
static int merge_trivial(git_index **index, const char *ours, const char *theirs, bool ancestor_use_parent)
static int merge_trivial(git_index **index, const char *ours, const char *theirs)
{
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
@@ -42,12 +42,8 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
if (!ancestor_use_parent) {
cl_git_pass(git_merge_base(&ancestor_oid, repo, git_commit_id(our_commit), git_commit_id(their_commit)));
cl_git_pass(git_commit_lookup(&ancestor_commit, repo, &ancestor_oid));
} else {
cl_git_pass(git_commit_parent(&ancestor_commit, their_commit, 0));
}
cl_git_pass(git_merge_base(&ancestor_oid, repo, git_commit_id(our_commit), git_commit_id(their_commit)));
cl_git_pass(git_commit_lookup(&ancestor_commit, repo, &ancestor_oid));
cl_git_pass(git_commit_tree(&ancestor_tree, ancestor_commit));
cl_git_pass(git_commit_tree(&our_tree, our_commit));
@@ -88,7 +84,7 @@ void test_merge_trees_trivial__2alt(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -103,7 +99,7 @@ void test_merge_trees_trivial__3alt(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -118,7 +114,7 @@ void test_merge_trees_trivial__4(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch"));
cl_assert((entry = git_index_get_bypath(result, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -136,7 +132,7 @@ void test_merge_trees_trivial__5alt_1(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -151,7 +147,7 @@ void test_merge_trees_trivial__5alt_2(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -167,7 +163,7 @@ void test_merge_trees_trivial__6(void)
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
@@ -185,7 +181,7 @@ void test_merge_trees_trivial__8(void)
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-8.txt", 0)) == NULL);
@@ -203,7 +199,7 @@ void test_merge_trees_trivial__7(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -222,7 +218,7 @@ void test_merge_trees_trivial__10(void)
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 0)) == NULL);
@@ -240,7 +236,7 @@ void test_merge_trees_trivial__9(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -259,7 +255,7 @@ void test_merge_trees_trivial__13(void)
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-13.txt", 0));
cl_git_pass(git_oid__fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b", GIT_OID_SHA1));
@@ -278,7 +274,7 @@ void test_merge_trees_trivial__14(void)
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-14-branch.txt", 0));
cl_git_pass(git_oid__fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9", GIT_OID_SHA1));
@@ -296,7 +292,7 @@ void test_merge_trees_trivial__11(void)
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch", false));
cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch"));
cl_assert((entry = git_index_get_bypath(result, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -308,22 +304,3 @@ void test_merge_trees_trivial__11(void)
git_index_free(result);
}
/* 15: ancest:remote^, head:head, remote:remote = result:no merge */
void test_merge_trees_trivial__15(void)
{
git_index *result;
const git_index_entry *entry;
/* Can't use merge_trivialfalsehere because a different ancestor is used. */
cl_git_pass(merge_trivial(&result, "trivial-15", "trivial-15-branch", true));
cl_assert((entry = git_index_get_bypath(result, "another-new-empty-15.txt", GIT_INDEX_STAGE_NORMAL)) == NULL);
cl_assert((entry = git_index_get_bypath(result, "another-new-empty-15.txt", GIT_INDEX_STAGE_ANCESTOR)));
cl_assert((entry = git_index_get_bypath(result, "another-new-empty-15.txt", GIT_INDEX_STAGE_OURS)) == NULL);
cl_assert((entry = git_index_get_bypath(result, "another-new-empty-15.txt", GIT_INDEX_STAGE_THEIRS)));
cl_assert(merge_trivial_conflict_entrycount(result) == 2);
git_index_free(result);
}

View File

@@ -1 +0,0 @@
0000000000000000000000000000000000000000 c452c5eb5aacf204fc95a55d1eb9668736fecfb6 Gregory Herrero <gregory.herrero@oracle.com> 1705326305 +0100 push

View File

@@ -1,2 +0,0 @@
0000000000000000000000000000000000000000 6706996f054c6af4fec7c77939d00e2f486dab4c Gregory Herrero <gregory.herrero@oracle.com> 1705326302 +0100 push
6706996f054c6af4fec7c77939d00e2f486dab4c c5be2acabac675af81df8bb70400235af2a9c225 Gregory Herrero <gregory.herrero@oracle.com> 1705326412 +0100 push

Binary file not shown.

View File

@@ -0,0 +1,3 @@
x¥NI
1ôœWô]<5D>žì/þÀ´<>Žãa&#~ß(þÀ:ÕFQ\—åÖAÛ¸éMtrš8K0YàK&Ž¥Xk¢w—É™"è$pPwj²vÕ\RðhÑgI<>=ŘK*SDaMÚ*zö¹68åµ ç¹.<2E>ºÂ^†ûaGù?µãº`
­q6YØâ€î8ÛåÏÅ3­W<C2AD>^áBM½ùiQ†

View File

@@ -1,4 +0,0 @@
x¥ÎAj1 @Ѭ}
ïCyFc(%»ö²,g2qn¡·o GÈö->_ú¾oÃÏ1†©úP‰3Õ
Ȉ¬T
žQbÀÐ*¨œ³{°é}xJ@9SƒˆBܰ©$I)/¹èÜðL• ŠãŸ±vó_¦×nþ[ÍÔºÿ¸¾`Z_péÆrÓIúþéC¸Ì„@þÀ=õy;ôÝŽ¶ýn|;…x*ÆwY'÷äIS

View File

@@ -0,0 +1,2 @@
x<01><>A
B1C]<5D><14>¤<>س<EFBFBD> "n<><6E><17>س)<><7F>Bصً[إ<1B> صR¤أ^<5E>Moج<10>3<EFBFBD><33>c:d غc<D8BA><06>ْؤhCِ<43>i2FإG<D8A5>k<EFBFBD>Kzإ<7A>ـ:ط<>ض<05>ا<D988><D8A7>[<5B>ز<EFBFBD>j9<6A> zBً0Xظي!5و8ُ<38>ه<EFBFBD><D987>E<EFBFBD>ؤ;4~ت*uQo<51>$D<>

View File

@@ -0,0 +1,3 @@
x¥OIj1ÌY¯è»!´¶‘Áøâä­VÉA£ ËøûM~<7E>E÷Ö~&o>æ<10>ÌZ;§uB[¡JärN9z)ÚVÄb¼ú¥!Ç.Rj

‡$ÈŘKª:¢°!c ÝçÞ\˃F<C692>ï½·[?àKûbyê“{;ƒ<18>õÞ œpA-w<><77>òϵS[_iÀì<C380>{WOG‰Rï

View File

@@ -0,0 +1 @@
ea789495e0a72efadcd0f86a48f4c9ed435bb8a3

View File

@@ -0,0 +1 @@
ab347abd8cda4a0e3b8bb42bb620c0c72c7df779

View File

@@ -1 +0,0 @@
c452c5eb5aacf204fc95a55d1eb9668736fecfb6

View File

@@ -1 +0,0 @@
c5be2acabac675af81df8bb70400235af2a9c225