2009-01-16 16:00:02 +08:00
|
|
|
#!/bin/sh
|
2009-04-07 16:21:20 +08:00
|
|
|
# git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
|
2009-01-16 16:00:02 +08:00
|
|
|
# This script is typically launched by using the 'git difftool'
|
|
|
|
# convenience command.
|
|
|
|
#
|
2010-01-16 11:10:03 +08:00
|
|
|
# Copyright (c) 2009, 2010 David Aguilar
|
2009-01-16 16:00:02 +08:00
|
|
|
|
2009-04-08 15:17:20 +08:00
|
|
|
TOOL_MODE=diff
|
|
|
|
. git-mergetool--lib
|
|
|
|
|
2009-04-07 16:21:22 +08:00
|
|
|
# difftool.prompt controls the default prompt/no-prompt behavior
|
|
|
|
# and is overridden with $GIT_DIFFTOOL*_PROMPT.
|
2009-01-16 16:00:02 +08:00
|
|
|
should_prompt () {
|
2010-01-23 00:36:36 +08:00
|
|
|
prompt_merge=$(git config --bool mergetool.prompt || echo true)
|
|
|
|
prompt=$(git config --bool difftool.prompt || echo $prompt_merge)
|
2011-08-18 15:23:44 +08:00
|
|
|
if test "$prompt" = true
|
|
|
|
then
|
2009-04-07 16:21:22 +08:00
|
|
|
test -z "$GIT_DIFFTOOL_NO_PROMPT"
|
|
|
|
else
|
|
|
|
test -n "$GIT_DIFFTOOL_PROMPT"
|
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
}
|
|
|
|
|
2010-01-10 12:02:42 +08:00
|
|
|
# Indicates that --extcmd=... was specified
|
|
|
|
use_ext_cmd () {
|
|
|
|
test -n "$GIT_DIFFTOOL_EXTCMD"
|
|
|
|
}
|
|
|
|
|
2009-01-16 16:00:02 +08: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 15:23:44 +08:00
|
|
|
if should_prompt
|
|
|
|
then
|
2013-02-10 09:21:25 +08:00
|
|
|
printf "\nViewing: '%s'\n" "$MERGED"
|
2011-08-18 15:23:44 +08:00
|
|
|
if use_ext_cmd
|
|
|
|
then
|
2011-10-08 21:10:15 +08:00
|
|
|
printf "Launch '%s' [Y/n]: " \
|
2010-01-10 12:02:42 +08:00
|
|
|
"$GIT_DIFFTOOL_EXTCMD"
|
|
|
|
else
|
2011-10-08 21:10:15 +08:00
|
|
|
printf "Launch '%s' [Y/n]: " "$merge_tool"
|
|
|
|
fi
|
|
|
|
if read ans && test "$ans" = n
|
|
|
|
then
|
|
|
|
return
|
2010-01-10 12:02:42 +08:00
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
fi
|
|
|
|
|
2011-08-18 15:23:44 +08:00
|
|
|
if use_ext_cmd
|
|
|
|
then
|
2010-12-14 17:18:35 +08:00
|
|
|
export BASE
|
2010-01-16 06:03:44 +08:00
|
|
|
eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
|
2010-01-10 12:02:42 +08:00
|
|
|
else
|
|
|
|
run_merge_tool "$merge_tool"
|
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
}
|
|
|
|
|
2011-08-18 15:23:44 +08:00
|
|
|
if ! use_ext_cmd
|
|
|
|
then
|
|
|
|
if test -n "$GIT_DIFF_TOOL"
|
|
|
|
then
|
2010-01-10 12:02:42 +08:00
|
|
|
merge_tool="$GIT_DIFF_TOOL"
|
|
|
|
else
|
|
|
|
merge_tool="$(get_merge_tool)" || exit
|
|
|
|
fi
|
2009-04-12 11:41:56 +08:00
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
|
2012-04-24 02:23:41 +08:00
|
|
|
if test -n "$GIT_DIFFTOOL_DIRDIFF"
|
|
|
|
then
|
|
|
|
LOCAL="$1"
|
|
|
|
REMOTE="$2"
|
|
|
|
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"
|
|
|
|
shift 7
|
|
|
|
done
|
|
|
|
fi
|