]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mergetool: add per-tool support and overrides for the hideResolved flag
authorSeth House <seth@eseth.com>
Tue, 9 Feb 2021 20:07:12 +0000 (13:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Feb 2021 22:09:16 +0000 (14:09 -0800)
Add a per-tool override flag so that users may enable the flag for one
tool and disable it for another by setting
`mergetool.<tool>.hideResolved` to `false`.

In addition, the author or maintainer of a mergetool may optionally
override the default `hideResolved` value for that mergetool. If the
`mergetools/<tool>` shell script contains a `hide_resolved_enabled`
function it will be called when the mergetool is invoked and the return
value will be used as the default for the `hideResolved` flag.

    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@kdbg.org>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Seth House <seth@eseth.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/mergetool.txt
git-mergetool--lib.sh
git-mergetool.sh

index b858191970c35c5fcc9e6573585743f55a35b604..90f76f5b9ba8ddd82ecc4ef3f89185f8e8298f23 100644 (file)
@@ -13,6 +13,11 @@ 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::
+       Allows the user to override the global `mergetool.hideResolved` value
+       for a specific tool. 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
index e059b3559e02dae35ff727e2d62a95521edad493..11f00dde41b622fec520fa1195993b55717242fd 100644 (file)
@@ -164,6 +164,10 @@ setup_tool () {
                return 1
        }
 
+       hide_resolved_enabled () {
+               return 0
+       }
+
        translate_merge_tool_path () {
                echo "$1"
        }
index e5eac935f3fbcffeb1543bdd73cd6b6f3f82bc32..911470a5b2c7aac6224964b7b0f39a3d72a9a985 100755 (executable)
@@ -333,7 +333,41 @@ merge_file () {
        checkout_staged_file 2 "$MERGED" "$LOCAL"
        checkout_staged_file 3 "$MERGED" "$REMOTE"
 
-       if test "$(git config --type=bool mergetool.hideResolved)" != "false"
+       # hideResolved preferences hierarchy.
+       global_config="mergetool.hideResolved"
+       tool_config="mergetool.${merge_tool}.hideResolved"
+
+       if enabled=$(git config --type=bool "$tool_config")
+       then
+               # The user has a specific preference for a specific tool and no
+               # other preferences should override that.
+               : ;
+       elif enabled=$(git config --type=bool "$global_config")
+       then
+               # The user has a general preference for all tools.
+               #
+               # 'true' means the user likes the feature so we should use it
+               # where possible but tool authors can still override.
+               #
+               # 'false' means the user doesn't like the feature so we should
+               # not use it anywhere.
+               if test "$enabled" = true && hide_resolved_enabled
+               then
+                   enabled=true
+               else
+                   enabled=false
+               fi
+       else
+               # The user does not have a preference. Ask the tool.
+               if hide_resolved_enabled
+               then
+                   enabled=true
+               else
+                   enabled=false
+               fi
+       fi
+
+       if test "$enabled" = true
        then
                hide_resolved
        fi