git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 1/2] mergetool: add automerge configuration

From
Seth House <seth@eseth.com>
Date
Dec 27, 2020, 20:58 UTC
Message-ID
<20201227205835.502556-2-seth@eseth.com>
In-Reply-To
<20201227205835.502556-1-seth@eseth.com>
From: Felipe Contreras <felipe.contreras@gmail.com>

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.

In order to unobtrusively do this, add a new configuration: mergetool.autoMerge.

See Seth House's blog post [1] for the idea, and the rationale.
[1] https://www.eseth.org/2020/mergetools.html
Original-idea-by: Seth House <seth@eseth.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/config/mergetool.txt |  3 +++
 git-mergetool.sh                   | 10 ++++++++++
 t/t7610-mergetool.sh               | 18 ++++++++++++++++++
 3 files changed, 31 insertions(+)
diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 16a27443a3..43af7a96f9 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -61,3 +61,6 @@ mergetool.writeToTemp::
 
 mergetool.prompt::
 	Prompt before each invocation of the merge resolution program.
+
+mergetool.autoMerge::
+	Automatically resolve conflicts that don't require user intervention.
diff --git a/git-mergetool.sh b/git-mergetool.sh
index e3f6d543fb..6e86d3b492 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -274,6 +274,7 @@ merge_file () {
 		BASE=${BASE##*/}
 	fi
 
+	DIFF3="$MERGETOOL_TMPDIR/${BASE}_DIFF3_$$$ext"
 	BACKUP="$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext"
 	LOCAL="$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext"
 	REMOTE="$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext"
@@ -322,6 +323,15 @@ merge_file () {
 	checkout_staged_file 2 "$MERGED" "$LOCAL"
 	checkout_staged_file 3 "$MERGED" "$REMOTE"
 
+	if test "$(git config --bool mergetool.autoMerge)" = "true"
+	then
+		git merge-file --diff3 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
+		sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
+		sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
+		sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
+		rm -- "$DIFF3"
+	fi
+
 	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..b75c91199b 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -828,4 +828,22 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	test_cmp expect actual
 '
 
+test_expect_success 'mergetool automerge' '
+	test_config mergetool.automerge true &&
+	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.29.2
Previous: Junio C HamanoNext: Junio C Hamano
Message 20 of 80 in “mergetool: remove unconflicted lines”
  1. 0/1 mergetool: remove unconflicted linesFelipe Contreras, Dec 23, 2020
  2. 1/1 mergetool: add automerge configurationFelipe Contreras, Dec 23, 2020
  3. Junio C HamanoDec 23, 2020
  4. Felipe ContrerasDec 23, 2020
  5. Junio C HamanoDec 23, 2020
  6. Felipe ContrerasDec 24, 2020
  7. Junio C HamanoDec 24, 2020
  8. Felipe ContrerasDec 24, 2020
  9. Junio C HamanoDec 24, 2020
  10. Felipe ContrerasDec 24, 2020
  11. Junio C HamanoDec 24, 2020
  12. Felipe ContrerasDec 27, 2020
  13. Junio C HamanoDec 24, 2020
  14. Felipe ContrerasDec 24, 2020
  15. Johannes SchindelinDec 30, 2020
  16. Felipe ContrerasDec 30, 2020
  17. 0/1 mergetool: add automerge configurationSeth House, Dec 27, 2020
  18. 2/2 mergetool: Add per-tool support for the autoMerge flagSeth House, Dec 27, 2020
  19. Junio C HamanoDec 27, 2020
  20. 1/2 mergetool: add automerge configurationSeth House, Dec 27, 2020
  21. Junio C HamanoDec 27, 2020
  22. Seth HouseDec 27, 2020
  23. Junio C HamanoDec 27, 2020
  24. 0/2 mergetool: add automerge configurationSeth House, Dec 28, 2020
  25. 2/2 mergetool: Add per-tool support for the autoMerge flagSeth House, Dec 28, 2020
  26. Felipe ContrerasDec 28, 2020
  27. 1/2 mergetool: add automerge configurationSeth House, Dec 28, 2020
  28. 0/4 mergetool: add automerge configurationSeth House, Dec 28, 2020
  29. 1/4 mergetool: add automerge configurationSeth House, Dec 28, 2020
  30. Johannes SixtDec 28, 2020
  31. 2/4 mergetool: Add per-tool support for the autoMerge flagSeth House, Dec 28, 2020
  32. Junio C HamanoDec 28, 2020
  33. 4/4 mergetool: Add automerge_enabled tool-specific override functionSeth House, Dec 28, 2020
  34. Johannes SixtDec 28, 2020
  35. Junio C HamanoDec 28, 2020
  36. 3/4 mergetool: Break setup_tool out into separate initialization functionSeth House, Dec 28, 2020
  37. Johannes SixtDec 28, 2020
  38. 0/5 mergetool: add automerge configurationSeth House, Dec 28, 2020
  39. 5/5 mergetool: add automerge_enabled tool-specific override functionSeth House, Dec 28, 2020
  40. Felipe ContrerasDec 29, 2020
  41. Junio C HamanoJan 6, 2021
  42. Seth HouseJan 7, 2021
  43. Junio C HamanoJan 7, 2021
  44. Seth HouseJan 7, 2021
  45. Junio C HamanoJan 7, 2021
  46. Johannes SchindelinJan 8, 2021
  47. 3/5 mergetool: add per-tool support for the autoMerge flagSeth House, Dec 28, 2020
  48. 4/5 mergetool: break setup_tool out into separate initialization functionSeth House, Dec 28, 2020
  49. Johannes SixtDec 29, 2020
  50. Seth HouseDec 29, 2020
  51. 2/5 mergetool: alphabetize the mergetool config docsSeth House, Dec 28, 2020
  52. 1/5 mergetool: add automerge configurationSeth House, Dec 28, 2020
  53. 0/3 mergetool: add hideResolved configuration (was automerge)Seth House, Jan 30, 2021
  54. 3/3 mergetool: add per-tool support and overrides for the hideResolved flagSeth House, Jan 30, 2021
  55. Junio C HamanoJan 30, 2021
  56. 2/3 mergetool: break setup_tool out into separate initialization functionSeth House, Jan 30, 2021
  57. 1/3 mergetool: add hideResolved configurationSeth House, Jan 30, 2021
  58. Junio C HamanoJan 30, 2021
  59. 0/3 mergetool: add hideResolved configuration (was automerge)Seth House, Feb 9, 2021
  60. 2/3 mergetool: break setup_tool out into separate initialization functionSeth House, Feb 9, 2021
  61. 1/3 mergetool: add hideResolved configurationSeth House, Feb 9, 2021
  62. mergetool: do not enable hideResolved by defaultJonathan Nieder, Mar 9, 2021
  63. Seth HouseMar 9, 2021
  64. Jonathan NiederMar 10, 2021
  65. Junio C HamanoMar 10, 2021
  66. Junio C HamanoMar 11, 2021
  67. Junio C HamanoMar 12, 2021
  68. Jonathan NiederMar 12, 2021
  69. Junio C HamanoMar 12, 2021
  70. 0/2 mergetool: do not enable hideResolved by defaultJonathan Nieder, Mar 13, 2021
  71. 1/2 mergetool: do not enable hideResolved by defaultJonathan Nieder, Mar 13, 2021
  72. 2/2 doc: describe mergetool configuration in git-mergetool(1)Jonathan Nieder, Mar 13, 2021
  73. Junio C HamanoMar 13, 2021
  74. Junio C HamanoMar 13, 2021
  75. 3/3 mergetool: add per-tool support and overrides for the hideResolved flagSeth House, Feb 9, 2021
  76. Junio C HamanoFeb 9, 2021
  77. Seth HouseFeb 9, 2021
  78. Junio C HamanoDec 28, 2020
  79. Felipe ContrerasDec 28, 2020
  80. Felipe ContrerasDec 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.