git/t/t4069-remerge-diff.sh
Elijah Newren db757e8b8d show, log: provide a --remerge-diff capability
When this option is specified, we remerge all (two parent) merge commits
and diff the actual merge commit to the automatically created version,
in order to show how users removed conflict markers, resolved the
different conflict versions, and potentially added new changes outside
of conflict regions in order to resolve semantic merge problems (or,
possibly, just to hide other random changes).

This capability works by creating a temporary object directory and
marking it as the primary object store.  This makes it so that any blobs
or trees created during the automatic merge are easily removable
afterwards by just deleting all objects from the temporary object
directory.

There are a few ways that this implementation is suboptimal:
  * `log --remerge-diff` becomes slow, because the temporary object
    directory can fill with many loose objects while running
  * the log output can be muddied with misplaced "warning: cannot merge
    binary files" messages, since ll-merge.c unconditionally writes those
    messages to stderr while running instead of allowing callers to
    manage them.
  * important conflict and warning messages are simply dropped; thus for
    conflicts like modify/delete or rename/rename or file/directory which
    are not representable with content conflict markers, there may be no
    way for a user of --remerge-diff to know that there had been a
    conflict which was resolved (and which possibly motivated other
    changes in the merge commit).
  * when fixing the previous issue, note that some unimportant conflict
    and warning messages might start being included.  We should instead
    make sure these remain dropped.
Subsequent commits will address these issues.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-02 10:02:27 -08:00

92 lines
2 KiB
Bash
Executable file

#!/bin/sh
test_description='remerge-diff handling'
. ./test-lib.sh
# This test is ort-specific
if test "${GIT_TEST_MERGE_ALGORITHM}" != ort
then
skip_all="GIT_TEST_MERGE_ALGORITHM != ort"
test_done
fi
test_expect_success 'setup basic merges' '
test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
git add numbers &&
git commit -m base &&
git branch feature_a &&
git branch feature_b &&
git branch feature_c &&
git branch ab_resolution &&
git branch bc_resolution &&
git checkout feature_a &&
test_write_lines 1 2 three 4 5 6 7 eight 9 >numbers &&
git commit -a -m change_a &&
git checkout feature_b &&
test_write_lines 1 2 tres 4 5 6 7 8 9 >numbers &&
git commit -a -m change_b &&
git checkout feature_c &&
test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers &&
git commit -a -m change_c &&
git checkout bc_resolution &&
git merge --ff-only feature_b &&
# no conflict
git merge feature_c &&
git checkout ab_resolution &&
git merge --ff-only feature_a &&
# conflicts!
test_must_fail git merge feature_b &&
# Resolve conflict...and make another change elsewhere
test_write_lines 1 2 drei 4 5 6 7 acht 9 >numbers &&
git add numbers &&
git merge --continue
'
test_expect_success 'remerge-diff on a clean merge' '
git log -1 --oneline bc_resolution >expect &&
git show --oneline --remerge-diff bc_resolution >actual &&
test_cmp expect actual
'
test_expect_success 'remerge-diff with both a resolved conflict and an unrelated change' '
git log -1 --oneline ab_resolution >tmp &&
cat <<-EOF >>tmp &&
diff --git a/numbers b/numbers
index a1fb731..6875544 100644
--- a/numbers
+++ b/numbers
@@ -1,13 +1,9 @@
1
2
-<<<<<<< b0ed5cb (change_a)
-three
-=======
-tres
->>>>>>> 6cd3f82 (change_b)
+drei
4
5
6
7
-eight
+acht
9
EOF
# Hashes above are sha1; rip them out so test works with sha256
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
git show --oneline --remerge-diff ab_resolution >tmp &&
sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
test_cmp expect actual
'
test_done