2009-01-16 11:00:02 +03:00
|
|
|
#!/bin/sh
|
2009-04-07 12:21:20 +04:00
|
|
|
# git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
|
2009-01-16 11:00:02 +03:00
|
|
|
# This script is typically launched by using the 'git difftool'
|
|
|
|
# convenience command.
|
|
|
|
#
|
2010-01-16 06:10:03 +03:00
|
|
|
# Copyright (c) 2009, 2010 David Aguilar
|
2009-01-16 11:00:02 +03:00
|
|
|
|
2009-04-08 11:17:20 +04:00
|
|
|
TOOL_MODE=diff
|
|
|
|
. git-mergetool--lib
|
|
|
|
|
2009-04-07 12:21:22 +04:00
|
|
|
# difftool.prompt controls the default prompt/no-prompt behavior
|
|
|
|
# and is overridden with $GIT_DIFFTOOL*_PROMPT.
|
2009-01-16 11:00:02 +03:00
|
|
|
should_prompt () {
|
2010-01-22 19:36:36 +03:00
|
|
|
prompt_merge=$(git config --bool mergetool.prompt || echo true)
|
|
|
|
prompt=$(git config --bool difftool.prompt || echo $prompt_merge)
|
2011-08-18 11:23:44 +04:00
|
|
|
if test "$prompt" = true
|
|
|
|
then
|
2009-04-07 12:21:22 +04:00
|
|
|
test -z "$GIT_DIFFTOOL_NO_PROMPT"
|
|
|
|
else
|
|
|
|
test -n "$GIT_DIFFTOOL_PROMPT"
|
|
|
|
fi
|
2009-01-16 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
2010-01-10 07:02:42 +03:00
|
|
|
# Indicates that --extcmd=... was specified
|
|
|
|
use_ext_cmd () {
|
|
|
|
test -n "$GIT_DIFFTOOL_EXTCMD"
|
|
|
|
}
|
|
|
|
|
2009-01-16 11:00:02 +03:00
|
|
|
launch_merge_tool () {
|
|
|
|
# Merged is the filename as it appears in the work tree
|
|
|
|
# Local is the contents of a/filename
|
|
|
|
# Remote is the contents of b/filename
|
|
|
|
# Custom merge tool commands might use $BASE so we provide it
|
|
|
|
MERGED="$1"
|
|
|
|
LOCAL="$2"
|
|
|
|
REMOTE="$3"
|
|
|
|
BASE="$1"
|
|
|
|
|
|
|
|
# $LOCAL and $REMOTE are temporary files so prompt
|
|
|
|
# the user with the real $MERGED name before launching $merge_tool.
|
2011-08-18 11:23:44 +04:00
|
|
|
if should_prompt
|
|
|
|
then
|
2013-12-06 03:38:46 +04:00
|
|
|
printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
|
|
|
|
"$GIT_DIFF_PATH_TOTAL" "$MERGED"
|
2011-08-18 11:23:44 +04:00
|
|
|
if use_ext_cmd
|
|
|
|
then
|
2016-04-12 17:44:20 +03:00
|
|
|
printf "Launch '%s' [Y/n]? " \
|
2010-01-10 07:02:42 +03:00
|
|
|
"$GIT_DIFFTOOL_EXTCMD"
|
|
|
|
else
|
2016-04-12 17:44:20 +03:00
|
|
|
printf "Launch '%s' [Y/n]? " "$merge_tool"
|
2011-10-08 17:10:15 +04:00
|
|
|
fi
|
2014-10-26 11:09:20 +03:00
|
|
|
read ans || return
|
|
|
|
if test "$ans" = n
|
2011-10-08 17:10:15 +04:00
|
|
|
then
|
|
|
|
return
|
2010-01-10 07:02:42 +03:00
|
|
|
fi
|
2009-01-16 11:00:02 +03:00
|
|
|
fi
|
|
|
|
|
2011-08-18 11:23:44 +04:00
|
|
|
if use_ext_cmd
|
|
|
|
then
|
2010-12-14 12:18:35 +03:00
|
|
|
export BASE
|
2010-01-16 01:03:44 +03:00
|
|
|
eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
|
2010-01-10 07:02:42 +03:00
|
|
|
else
|
2021-02-09 23:07:11 +03:00
|
|
|
initialize_merge_tool "$merge_tool"
|
|
|
|
# ignore the error from the above --- run_merge_tool
|
|
|
|
# will diagnose unusable tool by itself
|
2010-01-10 07:02:42 +03:00
|
|
|
run_merge_tool "$merge_tool"
|
|
|
|
fi
|
2009-01-16 11:00:02 +03:00
|
|
|
}
|
|
|
|
|
2011-08-18 11:23:44 +04:00
|
|
|
if ! use_ext_cmd
|
|
|
|
then
|
|
|
|
if test -n "$GIT_DIFF_TOOL"
|
|
|
|
then
|
2010-01-10 07:02:42 +03:00
|
|
|
merge_tool="$GIT_DIFF_TOOL"
|
|
|
|
else
|
2019-04-29 09:21:08 +03:00
|
|
|
merge_tool="$(get_merge_tool)"
|
mergetool: new config guiDefault supports auto-toggling gui by DISPLAY
When no merge.tool or diff.tool is configured or manually selected, the
selection of a default tool is sensitive to the DISPLAY variable; in a
GUI session a gui-specific tool will be proposed if found, and
otherwise a terminal-based one. This "GUI-optimizing" behavior is
important because a GUI can make a huge difference to a user's ability
to understand and correctly complete a non-trivial conflicting merge.
Some time ago the merge.guitool and diff.guitool config options were
introduced to enable users to configure both a GUI tool, and a non-GUI
tool (with fallback if no GUI tool configured), in the same environment.
Unfortunately, the --gui argument introduced to support the selection of
the guitool is still explicit. When using configured tools, there is no
equivalent of the no-tool-configured "propose a GUI tool if we are in a GUI
environment" behavior.
As proposed in <xmqqmtb8jsej.fsf@gitster.g>, introduce new configuration
options, difftool.guiDefault and mergetool.guiDefault, supporting a special
value "auto" which causes the corresponding tool or guitool to be selected
depending on the presence of a non-empty DISPLAY value. Also support "true"
to say "default to the guitool (unless --no-gui is passed on the
commandline)", and "false" as the previous default behavior when these new
configuration options are not specified.
Signed-off-by: Tao Klerks <tao@klerks.biz>
Acked-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-18 18:27:43 +03:00
|
|
|
subshell_exit_status=$?
|
|
|
|
if test $subshell_exit_status -gt 1
|
|
|
|
then
|
|
|
|
exit $subshell_exit_status
|
|
|
|
fi
|
2010-01-10 07:02:42 +03:00
|
|
|
fi
|
2009-04-12 07:41:56 +04:00
|
|
|
fi
|
2009-01-16 11:00:02 +03:00
|
|
|
|
2012-04-23 22:23:41 +04:00
|
|
|
if test -n "$GIT_DIFFTOOL_DIRDIFF"
|
|
|
|
then
|
|
|
|
LOCAL="$1"
|
|
|
|
REMOTE="$2"
|
2021-02-09 23:07:11 +03:00
|
|
|
initialize_merge_tool "$merge_tool"
|
|
|
|
# ignore the error from the above --- run_merge_tool
|
|
|
|
# will diagnose unusable tool by itself
|
2012-04-23 22:23:41 +04:00
|
|
|
run_merge_tool "$merge_tool" false
|
|
|
|
else
|
|
|
|
# Launch the merge tool on each path provided by 'git diff'
|
|
|
|
while test $# -gt 6
|
|
|
|
do
|
|
|
|
launch_merge_tool "$1" "$2" "$5"
|
2014-10-27 04:15:42 +03:00
|
|
|
status=$?
|
2016-08-16 00:54:39 +03:00
|
|
|
if test $status -ge 126
|
|
|
|
then
|
|
|
|
# Command not found (127), not executable (126) or
|
|
|
|
# exited via a signal (>= 128).
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
2014-10-27 04:15:42 +03:00
|
|
|
if test "$status" != 0 &&
|
|
|
|
test "$GIT_DIFFTOOL_TRUST_EXIT_CODE" = true
|
|
|
|
then
|
|
|
|
exit $status
|
|
|
|
fi
|
2012-04-23 22:23:41 +04:00
|
|
|
shift 7
|
|
|
|
done
|
|
|
|
fi
|
2014-11-21 04:20:28 +03:00
|
|
|
|
|
|
|
exit 0
|