Skip to content

Commit 2464456

Browse files
davvidgitster
authored andcommitted
contrib/difftool: use a separate config namespace for difftool commands
Some users have different mergetool and difftool settings, so teach difftool to read config vars from the difftool.* namespace. This allows having distinct configurations for the diff and merge scenarios. We don't want to force existing users to set new values for no reason so difftool falls back to existing mergetool config variables when the difftool equivalents are not defined. Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4e52f0 commit 2464456

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

contrib/difftool/git-difftool

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
55
# git-difftool-helper script. This script exports
66
# GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and
7-
# GIT_DIFFTOOL_NO_PROMPT and GIT_MERGE_TOOL for use by git-difftool-helper.
7+
# GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool-helper.
88
# Any arguments that are unknown to this script are forwarded to 'git diff'.
99

1010
use strict;
@@ -49,12 +49,12 @@ sub generate_command
4949
}
5050
if ($arg eq '-t' or $arg eq '--tool') {
5151
usage() if $#ARGV <= $idx;
52-
$ENV{GIT_MERGE_TOOL} = $ARGV[$idx + 1];
52+
$ENV{GIT_DIFF_TOOL} = $ARGV[$idx + 1];
5353
$skip_next = 1;
5454
next;
5555
}
5656
if ($arg =~ /^--tool=/) {
57-
$ENV{GIT_MERGE_TOOL} = substr($arg, 7);
57+
$ENV{GIT_DIFF_TOOL} = substr($arg, 7);
5858
next;
5959
}
6060
if ($arg eq '--no-prompt') {

contrib/difftool/git-difftool-helper

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ launch_merge_tool () {
128128
cleanup_temp_files
129129
}
130130

131-
# Verifies that mergetool.<tool>.cmd exists
131+
# Verifies that (difftool|mergetool).<tool>.cmd exists
132132
valid_custom_tool() {
133+
merge_tool_cmd="$(git config difftool.$1.cmd)"
134+
test -z "$merge_tool_cmd" &&
133135
merge_tool_cmd="$(git config mergetool.$1.cmd)"
134136
test -n "$merge_tool_cmd"
135137
}
@@ -150,8 +152,11 @@ valid_tool() {
150152
}
151153

152154
# Sets up the merge_tool_path variable.
153-
# This handles the mergetool.<tool>.path configuration.
155+
# This handles the difftool.<tool>.path configuration.
156+
# This also falls back to mergetool defaults.
154157
init_merge_tool_path() {
158+
merge_tool_path=$(git config difftool."$1".path)
159+
test -z "$merge_tool_path" &&
155160
merge_tool_path=$(git config mergetool."$1".path)
156161
if test -z "$merge_tool_path"; then
157162
case "$1" in
@@ -165,15 +170,19 @@ init_merge_tool_path() {
165170
fi
166171
}
167172

168-
# Allow the GIT_MERGE_TOOL variable to provide a default value
173+
# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
169174
test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
175+
test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
170176

171-
# If not merge tool was specified then use the merge.tool
177+
# If merge tool was not specified then use the diff.tool
172178
# configuration variable. If that's invalid then reset merge_tool.
179+
# Fallback to merge.tool.
173180
if test -z "$merge_tool"; then
181+
merge_tool=$(git config diff.tool)
182+
test -z "$merge_tool" &&
174183
merge_tool=$(git config merge.tool)
175184
if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
176-
echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
185+
echo >&2 "git config option diff.tool set to unknown tool: $merge_tool"
177186
echo >&2 "Resetting to default..."
178187
unset merge_tool
179188
fi

contrib/difftool/git-difftool.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ OPTIONS
3232
vimdiff, gvimdiff, ecmerge, and opendiff
3333
+
3434
If a merge resolution program is not specified, 'git-difftool'
35-
will use the configuration variable `merge.tool`. If the
36-
configuration variable `merge.tool` is not set, 'git difftool'
35+
will use the configuration variable `diff.tool`. If the
36+
configuration variable `diff.tool` is not set, 'git-difftool'
3737
will pick a suitable default.
3838
+
3939
You can explicitly provide a full path to the tool by setting the
40-
configuration variable `mergetool.<tool>.path`. For example, you
40+
configuration variable `difftool.<tool>.path`. For example, you
4141
can configure the absolute path to kdiff3 by setting
42-
`mergetool.kdiff3.path`. Otherwise, 'git-difftool' assumes the
42+
`difftool.kdiff3.path`. Otherwise, 'git-difftool' assumes the
4343
tool is available in PATH.
4444
+
4545
Instead of running one of the known merge tool programs,
4646
'git-difftool' can be customized to run an alternative program
4747
by specifying the command line to invoke in a configuration
48-
variable `mergetool.<tool>.cmd`.
48+
variable `difftool.<tool>.cmd`.
4949
+
5050
When 'git-difftool' is invoked with this tool (either through the
51-
`-t` or `--tool` option or the `merge.tool` configuration variable)
51+
`-t` or `--tool` option or the `diff.tool` configuration variable)
5252
the configured command line will be invoked with the following
5353
variables available: `$LOCAL` is set to the name of the temporary
5454
file containing the contents of the diff pre-image and `$REMOTE`
@@ -61,24 +61,24 @@ with custom merge tool commands and has the same value as `$LOCAL`.
6161

6262
CONFIG VARIABLES
6363
----------------
64-
merge.tool::
65-
The default merge tool to use.
66-
+
67-
See the `--tool=<tool>` option above for more details.
64+
'git-difftool' falls back to 'git-mergetool' config variables when the
65+
difftool equivalents have not been defined.
6866

69-
merge.keepBackup::
70-
The original, unedited file content can be saved to a file with
71-
a `.orig` extension. Defaults to `true` (i.e. keep the backup files).
67+
diff.tool::
68+
The default merge tool to use.
7269

73-
mergetool.<tool>.path::
70+
difftool.<tool>.path::
7471
Override the path for the given tool. This is useful in case
7572
your tool is not in the PATH.
7673

77-
mergetool.<tool>.cmd::
74+
difftool.<tool>.cmd::
7875
Specify the command to invoke the specified merge tool.
7976
+
8077
See the `--tool=<tool>` option above for more details.
8178

79+
merge.keepBackup::
80+
The original, unedited file content can be saved to a file with
81+
a `.orig` extension. Defaults to `true` (i.e. keep the backup files).
8282

8383
SEE ALSO
8484
--------

0 commit comments

Comments
 (0)