git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v4 0/1] mergetool: add configuration to remove unconflicted lines
@ 2020-12-18 12:49 Felipe Contreras
  2020-12-18 12:49 ` [PATCH v4 1/1] mergetool: add automerge configuration Felipe Contreras
  0 siblings, 1 reply; 6+ messages in thread
From: Felipe Contreras @ 2020-12-18 12:49 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, David Aguilar, Johannes Sixt, Seth House,
	Felipe Contreras

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-21  5:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 12:49 [PATCH v4 0/1] mergetool: add configuration to remove unconflicted lines Felipe Contreras
2020-12-18 12:49 ` [PATCH v4 1/1] mergetool: add automerge configuration Felipe Contreras
2020-12-19 11:14   ` Phillip Wood
2020-12-19 12:53     ` Felipe Contreras
2020-12-20 19:21       ` Phillip Wood
2020-12-21  3:04         ` Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).