[PATCH v10 3/3] mergetool: add per-tool support and overrides for the hideResolved flag

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

 



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. In
addition, the author or maintainer of a mergetool may optionally elect
to set the default `hideResolved` value for that mergetool.

To disable the feature for a specific tool, edit the `mergetools/<tool>`
shell script for that tool and add a `hide_resolved_enabled` function:

    hide_resolved_enabled () {
        return 1
    }

Disabling may be desirable if the mergetool wants or needs access to the
original, unmodified 'LOCAL' and 'REMOTE' versions of the conflicted
file. For example:

- A tool may use a custom conflict resolution algorithm and prefer to
  ignore the results of Git's conflict resolution.
- A tool may want to visually compare/constrast the version of the file
  from before the merge (saved to 'LOCAL', 'REMOTE', and 'BASE') with
  Git's conflict resolution results (saved to 'MERGED').

Helped-by: Johannes Sixt <j6t@xxxxxxxx>
Helped-by: Junio C Hamano <gitster@xxxxxxxxx>
Signed-off-by: Seth House <seth@xxxxxxxxx>
---
 Documentation/config/mergetool.txt |  6 ++++++
 git-mergetool--lib.sh              |  4 ++++
 git-mergetool.sh                   | 14 ++++++++++++--
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt
index 3171bacf91..046816fb07 100644
--- a/Documentation/config/mergetool.txt
+++ b/Documentation/config/mergetool.txt
@@ -13,6 +13,12 @@ mergetool.<tool>.cmd::
 	merged; 'MERGED' contains the name of the file to which the merge
 	tool should write the results of a successful merge.
 
+mergetool.<tool>.hideResolved::
+	A mergetool-specific override for the global `mergetool.hideResolved`
+	configuration flag. This allows individual mergetools to enable or
+	disable the flag regardless of the global setting. See
+	`mergetool.hideResolved` for the full description.
+
 mergetool.<tool>.trustExitCode::
 	For a custom merge command, specify whether the exit code of
 	the merge command can be used to determine whether the merge was
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index e059b3559e..11f00dde41 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -164,6 +164,10 @@ setup_tool () {
 		return 1
 	}
 
+	hide_resolved_enabled () {
+		return 0
+	}
+
 	translate_merge_tool_path () {
 		echo "$1"
 	}
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 865f12551a..6cf3884277 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -333,9 +333,19 @@ merge_file () {
 	checkout_staged_file 2 "$MERGED" "$LOCAL"
 	checkout_staged_file 3 "$MERGED" "$REMOTE"
 
-	if test "$(git config --get mergetool.hideResolved)" != "false"
+	# hideResolved preferences hierarchy:
+	# First respect user's tool-specific configuration if exists.
+	if test "$(git config --get "mergetool.$merge_tool.hideResolved")" != "false"
 	then
-		hide_resolved
+		# Next respect tool-specified configuration.
+		if hide_resolved_enabled
+		then
+			# Finally respect if user has a global disable.
+			if test "$(git config --get "mergetool.hideResolved")" != "false"
+			then
+				hide_resolved
+			fi
+		fi
 	fi
 
 	if test -z "$local_mode" || test -z "$remote_mode"
-- 
2.29.2





[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