Skip to content

Commit 8e4ec33

Browse files
newrengitster
authored andcommitted
merge-recursive: fix the diff3 common ancestor label for virtual commits
In commit 743474c ("merge-recursive: provide a better label for diff3 common ancestor", 2019-08-17), the label for the common ancestor was changed from always being "merged common ancestors" to instead be based on the number of merge bases: >=2: "merged common ancestors" 1: <abbreviated commit hash> 0: "<empty tree>" Unfortunately, this did not take into account that when we have a single merge base, that merge base could be fake or constructed. In such cases, this resulted in a label of "00000000". Of course, the previous label of "merged common ancestors" was also misleading for this case. Since we have an API that is explicitly about creating fake merge base commits in merge_recursive_generic(), we should provide a better label when using that API with one merge base. So, when merge_recursive_generic() is called with one merge base, set the label to: "constructed merge base" Note that callers of merge_recursive_generic() include the builtin commands git-am (in combination with git apply --build-fake-ancestor), git-merge-recursive, and git-stash. Helped-by: Jeff King <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4615a8c commit 8e4ec33

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

merge-recursive.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,8 @@ static int merge_recursive_internal(struct merge_options *opt,
35503550
merged_merge_bases = make_virtual_commit(opt->repo, tree,
35513551
"ancestor");
35523552
ancestor_name = "empty tree";
3553+
} else if (opt->ancestor) {
3554+
ancestor_name = opt->ancestor;
35533555
} else if (merge_bases) {
35543556
ancestor_name = "merged common ancestors";
35553557
} else {
@@ -3689,7 +3691,8 @@ int merge_recursive(struct merge_options *opt,
36893691
{
36903692
int clean;
36913693

3692-
assert(opt->ancestor == NULL);
3694+
assert(opt->ancestor == NULL ||
3695+
!strcmp(opt->ancestor, "constructed merge base"));
36933696

36943697
if (merge_start(opt, repo_get_commit_tree(opt->repo, h1)))
36953698
return -1;
@@ -3741,6 +3744,8 @@ int merge_recursive_generic(struct merge_options *opt,
37413744
oid_to_hex(merge_bases[i]));
37423745
commit_list_insert(base, &ca);
37433746
}
3747+
if (num_merge_bases == 1)
3748+
opt->ancestor = "constructed merge base";
37443749
}
37453750

37463751
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);

t/t6047-diff3-conflict-markers.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,17 @@ test_expect_success 'check multiple merge bases' '
186186
)
187187
'
188188

189+
test_expect_success 'rebase describes fake ancestor base' '
190+
test_create_repo rebase &&
191+
(
192+
cd rebase &&
193+
test_commit base file &&
194+
test_commit master file &&
195+
git checkout -b side HEAD^ &&
196+
test_commit side file &&
197+
test_must_fail git -c merge.conflictstyle=diff3 rebase master &&
198+
grep "||||||| constructed merge base" file
199+
)
200+
'
201+
189202
test_done

0 commit comments

Comments
 (0)