8000 merge: fix incorrect rename detection for empty files. by herrerog · Pull Request #6717 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

merge: fix incorrect rename detection for empty files. #6717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: merge: tree: add support for different ancestor.
Add a boolean option to merge_trivial() so that it can use theirs
parent instead of merge base as ancestor. This will be needed in the
following commit.

Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
  • Loading branch information
herrerog committed Jan 16, 2024
commit 334dd8da93cb80c353fb3b363bfb730383f09fb8
36 changes: 20 additions & 16 deletions tests/libgit2/merge/trees/trivial.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void test_merge_trees_trivial__cleanup(void)
}


static int merge_trivial(git_index **index, const char *ours, const char *theirs)
static int merge_trivial(git_index **index, const char *ours, const char *theirs, bool ancestor_use_parent)
{
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
Expand All @@ -42,8 +42,12 @@ 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));

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));
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_commit_tree(&ancestor_tree, ancestor_commit));
cl_git_pass(git_commit_tree(&our_tree, our_commit));
Expand Down Expand Up @@ -84,7 +88,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"));
cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch", false));

cl_assert(entry = git_index_get_bypath(result, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -99,7 +103,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"));
cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch", false));

cl_assert(entry = git_index_get_bypath(result, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -114,7 +118,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"));
cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch", false));

cl_assert((entry = git_index_get_bypath(result, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -132,7 +136,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"));
cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch", false));

cl_assert(entry = git_index_get_bypath(result, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -147,7 +151,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"));
cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch", false));

cl_assert(entry = git_index_get_bypath(result, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -163,7 +167,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"));
cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch", false));

cl_assert((entry = git_index_get_bypath(result, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
Expand All @@ -181,7 +185,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"));
cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch", false));

cl_assert((entry = git_index_get_bypath(result, "removed-in-8.txt", 0)) == NULL);

Expand All @@ -199,7 +203,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"));
cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch", false));

cl_assert((entry = git_index_get_bypath(result, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -218,7 +222,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"));
cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch", false));

cl_assert((entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 0)) == NULL);

Expand All @@ -236,7 +240,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"));
cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch", false));

cl_assert((entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand All @@ -255,7 +259,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"));
cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch", false));

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));
Expand All @@ -274,7 +278,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"));
cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch", false));

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));
Expand All @@ -292,7 +296,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"));
cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch", false));

cl_assert((entry = git_index_get_bypath(result, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
Expand Down
0