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

[PATCH v4 0/1] mergetool: add configuration to remove unconflicted lines

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Dec 18, 2020, 12:49 UTC
Message-ID
<20201218124905.1072514-1-felipe.contreras@gmail.com>
There's not much to say other that what the commit message of the patch says.
Changes since v3:
 * Turned on by default
 * Added a check for binary files since Junio brought them up
 * Added the marker-size implicitly as Junio requested
 * Changed the way files are generated in the tests, as Junio said
 * Improved the documentation
diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 43af7a96f9..7ce6d0d3ac 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -63,4 +63,4 @@ mergetool.prompt::
 	Prompt before each invocation of the merge resolution program.
 
 mergetool.autoMerge::
-	Automatically resolve conflicts that don't require user intervention.
+	Remove lines without conflicts from all the files. Defaults to `true`.
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 6e86d3b492..f4db0cac8d 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -239,6 +239,17 @@ checkout_staged_file () {
 	fi
 }
 
+auto_merge () {
+	git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
+	if test -s "$DIFF3"
+	then
+		sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
+		sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
+		sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
+	fi
+	rm -- "$DIFF3"
+}
+
 merge_file () {
 	MERGED="$1"
 
@@ -323,13 +334,9 @@ merge_file () {
 	checkout_staged_file 2 "$MERGED" "$LOCAL"
 	checkout_staged_file 3 "$MERGED" "$REMOTE"
 
-	if test "$(git config --bool mergetool.autoMerge)" = "true"
+	if test "$(git config --bool mergetool.autoMerge)" != "false"
 	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"
+		auto_merge
 	fi
 
 	if test -z "$local_mode" || test -z "$remote_mode"
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index b75c91199b..ccabd04823 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -832,16 +832,16 @@ 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 &&
+	test_write_lines >file1 base "" a &&
 	git commit -a -m "base" &&
-	echo -e "base\n\nc" >file1 &&
+	test_write_lines >file1 base "" c &&
 	git commit -a -m "remote update" &&
 	git checkout -b test${test_count}_a HEAD~ &&
-	echo -e "local\n\nb" >file1 &&
+	test_write_lines >file1 local "" b &&
 	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_write_lines >expect local "" c &&
 	test_cmp expect file1 &&
 	git commit -m "test resolved with mergetool"
 '

Felipe Contreras (1):
  mergetool: add automerge configuration

 Documentation/config/mergetool.txt |  3 +++
 git-mergetool.sh                   | 17 +++++++++++++++++
 t/t7610-mergetool.sh               | 18 ++++++++++++++++++
 3 files changed, 38 insertions(+)
-- 
2.30.0.rc0
Next: Felipe Contreras
Message 1 of 6 in “mergetool: add configuration to remove unconflicted lines”
  1. 0/1 mergetool: add configuration to remove unconflicted linesFelipe Contreras, Dec 18, 2020
  2. 1/1 mergetool: add automerge configurationFelipe Contreras, Dec 18, 2020
  3. Phillip WoodDec 19, 2020
  4. Felipe ContrerasDec 19, 2020
  5. Phillip WoodDec 20, 2020
  6. Felipe ContrerasDec 21, 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.