merge-tree: support including merge messages in output

When running `git merge-tree --write-tree`, we previously would only
return an exit status reflecting the cleanness of a merge, and print out
the toplevel tree of the resulting merge.  Merges also have
informational messages, such as:
  * "Auto-merging <PATH>"
  * "CONFLICT (content): ..."
  * "CONFLICT (file/directory)"
  * etc.
In fact, when non-content conflicts occur (such as file/directory,
modify/delete, add/add with differing modes, rename/rename (1to2),
etc.), these informational messages may be the only notification the
user gets since these conflicts are not representable in the contents
of the file.

Add a --[no-]messages option so that callers can request these messages
be included at the end of the output.  Include such messages by default
when there are conflicts, and omit them by default when the merge is
clean.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren
2022-06-18 00:20:49 +00:00
committed by Junio C Hamano
parent a34edae68a
commit a1a7811975
3 changed files with 97 additions and 8 deletions

View File

@ -103,4 +103,41 @@ test_expect_success 'Barf on too many arguments' '
grep "^usage: git merge-tree" expect
'
anonymize_hash() {
sed -e "s/[0-9a-f]\{40,\}/HASH/g" "$@"
}
test_expect_success 'test conflict notices and such' '
test_expect_code 1 git merge-tree --write-tree side1 side2 >out &&
anonymize_hash out >actual &&
# Expected results:
# "greeting" should merge with conflicts
# "numbers" should merge cleanly
# "whatever" has *both* a modify/delete and a file/directory conflict
cat <<-EOF >expect &&
HASH
Auto-merging greeting
CONFLICT (content): Merge conflict in greeting
Auto-merging numbers
CONFLICT (file/directory): directory in the way of whatever from side1; moving it to whatever~side1 instead.
CONFLICT (modify/delete): whatever~side1 deleted in side2 and modified in side1. Version side1 of whatever~side1 left in tree.
EOF
test_cmp expect actual
'
for opt in $(git merge-tree --git-completion-helper-all)
do
if test $opt = "--trivial-merge" || test $opt = "--write-tree"
then
continue
fi
test_expect_success "usage: --trivial-merge is incompatible with $opt" '
test_expect_code 128 git merge-tree --trivial-merge $opt side1 side2 side3
'
done
test_done