Skip to content

Commit 9d9cf23

Browse files
whiteingegitster
authored andcommitted
mergetool: add per-tool support and overrides for the hideResolved flag
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 <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Seth House <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de8dafb commit 9d9cf23

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

Documentation/config/mergetool.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ mergetool.<tool>.cmd::
1313
merged; 'MERGED' contains the name of the file to which the merge
1414
tool should write the results of a successful merge.
1515

16+
mergetool.<tool>.hideResolved::
17+
Allows the user to override the global `mergetool.hideResolved` value
18+
for a specific tool. See `mergetool.hideResolved` for the full
19+
description.
20+
1621
mergetool.<tool>.trustExitCode::
1722
For a custom merge command, specify whether the exit code of
1823
the merge command can be used to determine whether the merge was

git-mergetool--lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ setup_tool () {
164164
return 1
165165
}
166166

167+
hide_resolved_enabled () {
168+
return 0
169+
}
170+
167171
translate_merge_tool_path () {
168172
echo "$1"
169173
}

git-mergetool.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,41 @@ merge_file () {
333333
checkout_staged_file 2 "$MERGED" "$LOCAL"
334334
checkout_staged_file 3 "$MERGED" "$REMOTE"
335335

336-
if test "$(git config --type=bool mergetool.hideResolved)" != "false"
336+
# hideResolved preferences hierarchy.
337+
global_config="mergetool.hideResolved"
338+
tool_config="mergetool.${merge_tool}.hideResolved"
339+
340+
if enabled=$(git config --type=bool "$tool_config")
341+
then
342+
# The user has a specific preference for a specific tool and no
343+
# other preferences should override that.
344+
: ;
345+
elif enabled=$(git config --type=bool "$global_config")
346+
then
347+
# The user has a general preference for all tools.
348+
#
349+
# 'true' means the user likes the feature so we should use it
350+
# where possible but tool authors can still override.
351+
#
352+
# 'false' means the user doesn't like the feature so we should
353+
# not use it anywhere.
354+
if test "$enabled" = true && hide_resolved_enabled
355+
then
356+
enabled=true
357+
else
358+
enabled=false
359+
fi
360+
else
361+
# The user does not have a preference. Ask the tool.
362+
if hide_resolved_enabled
363+
then
364+
enabled=true
365+
else
366+
enabled=false
367+
fi
368+
fi
369+
370+
if test "$enabled" = true
337371
then
338372
hide_resolved
339373
fi

0 commit comments

Comments
 (0)