[RFC/PATCH v2] mergetool: use resolved conflicts in all the views

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It doesn't make sense to display easily-solvable conflicts in the
different views of all mergetools.

Only the chunks that warrant conflict markers should be displayed.

TODO: There should be a better way to get the BASE version (maybe add
--base to git mergetool). Or maybe a way to generate the three files in
one go.

See Seth House's blog post [1] for the idea and the rationale.

[1] https://www.eseth.org/2020/mergetools.html

Cc: Seth House <seth@xxxxxxxxx>
Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 git-mergetool.sh     | 11 +++++++++++
 t/t7610-mergetool.sh | 17 +++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index e3f6d543fb..2f71da4574 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -322,6 +322,17 @@ merge_file () {
 	checkout_staged_file 2 "$MERGED" "$LOCAL"
 	checkout_staged_file 3 "$MERGED" "$REMOTE"
 
+	# TODO Shouldn't merge-file have a --base option?
+	git merge-file --diff3 -q -p "$LOCAL" "$BASE" "$REMOTE" |
+		sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======$/,/^>>>>>>> /d' \
+			>"${BASE}_resolved"
+	git merge-file --ours -q -p "$LOCAL" "$BASE" "$REMOTE" >"${LOCAL}_resolved"
+	git merge-file --theirs -q -p "$LOCAL" "$BASE" "$REMOTE" >"${REMOTE}_resolved"
+
+	mv -f "${BASE}_resolved" "$BASE"
+	mv -f "${LOCAL}_resolved" "$LOCAL"
+	mv -f "${REMOTE}_resolved" "$REMOTE"
+
 	if test -z "$local_mode" || test -z "$remote_mode"
 	then
 		echo "Deleted merge conflict for '$MERGED':"
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 70afdd06fa..69260c4a46 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -828,4 +828,21 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	test_cmp expect actual
 '
 
+test_expect_success 'skip unnecessary chunks' '
+	test_when_finished "git reset --hard" &&
+	git checkout -b test${test_count}_b master &&
+	echo -e "base\n\na" >file1 &&
+	git commit -a -m "base" &&
+	echo -e "base\n\nc" >file1 &&
+	git commit -a -m "remote update" &&
+	git checkout -b test${test_count}_a HEAD~ &&
+	echo -e "local\n\nb" >file1 &&
+	git commit -a -m "local update" &&
+	test_must_fail git merge test${test_count}_b &&
+	yes "" | git mergetool file1 &&
+	echo -e "local\n\nc" >expect &&
+	test_cmp expect file1 &&
+	git commit -m "test resolved with mergetool"
+'
+
 test_done
-- 
2.30.0.rc0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux