diff mbox series

[v9,3/5] mergetool: add per-tool support for the autoMerge flag

Message ID 20201228192919.1195211-4-seth@eseth.com (mailing list archive)
State New, archived
Headers show
Series mergetool: add automerge configuration | expand

Commit Message

Seth House Dec. 28, 2020, 7:29 p.m. UTC
Keep the global mergetool flag and add a per-tool override flag so that
users may enable the flag for one tool and disable it for another.

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Seth House <seth@eseth.com>
---
 Documentation/config/mergetool.txt | 15 ++++++++++++++-
 git-mergetool.sh                   |  5 ++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 3291fa7102..bde472d49a 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -1,3 +1,9 @@ 
+mergetool.<tool>.autoMerge::
+	A mergetool-specific override for the global `mergetool.autoMerge`
+	configuration flag. This allows individual mergetools to enable or
+	disable the flag regardless of the global setting. See
+	`mergetool.autoMerge` for the full description.
+
 mergetool.<tool>.cmd::
 	Specify the command to invoke the specified merge tool.  The
 	specified command is evaluated in shell with the following
@@ -41,7 +47,14 @@  mergetool.meld.useAutoMerge::
 	default value.
 
 mergetool.autoMerge::
-	Remove lines without conflicts from all the files. Defaults to `true`.
+	During a merge Git will automatically resolve as many conflicts as
+	possible and then wrap conflict markers around any conflicts that it
+	cannot resolve. This flag consolidates the non-conflicting parts into
+	the corresponding 'LOCAL' and 'REMOTE' files so that only the
+	unresolved conflicts are presented to the merge tool. Can be overriden
+	per-tool via the `mergetool.<tool>.autoMerge` configuration variable.
+	Note: individual mergetool scripts can elect to ignore user preferences
+	entirely. Defaults to `true`.
 
 mergetool.keepBackup::
 	After performing a merge, the original file with conflict markers
diff --git a/git-mergetool.sh b/git-mergetool.sh
index f4db0cac8d..e3c7d78d1d 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -334,7 +334,10 @@  merge_file () {
 	checkout_staged_file 2 "$MERGED" "$LOCAL"
 	checkout_staged_file 3 "$MERGED" "$REMOTE"
 
-	if test "$(git config --bool mergetool.autoMerge)" != "false"
+	if test "$(
+		git config --get --bool "mergetool.$merge_tool.automerge" ||
+		git config --get --bool "mergetool.automerge" ||
+		echo true)" = true
 	then
 		auto_merge
 	fi