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.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2009 David Aguilar
|
|
|
|
|
2009-04-08 15:17:20 +08:00
|
|
|
# Load common functions from git-mergetool--lib
|
|
|
|
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 () {
|
2009-04-07 16:21:22 +08:00
|
|
|
prompt=$(git config --bool difftool.prompt || echo true)
|
|
|
|
if test "$prompt" = true; then
|
|
|
|
test -z "$GIT_DIFFTOOL_NO_PROMPT"
|
|
|
|
else
|
|
|
|
test -n "$GIT_DIFFTOOL_PROMPT"
|
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
}
|
|
|
|
|
2009-04-08 15:17:20 +08:00
|
|
|
# Sets up shell variables and runs a merge tool
|
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.
|
|
|
|
if should_prompt; then
|
|
|
|
printf "\nViewing: '$MERGED'\n"
|
|
|
|
printf "Hit return to launch '%s': " "$merge_tool"
|
|
|
|
read ans
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run the appropriate merge tool command
|
2009-04-08 15:17:20 +08:00
|
|
|
run_merge_tool "$merge_tool"
|
2009-01-16 16:00:02 +08:00
|
|
|
}
|
|
|
|
|
2009-03-09 17:12:36 +08:00
|
|
|
# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
|
2009-01-16 16:00:02 +08:00
|
|
|
test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
|
2009-03-09 17:12:36 +08:00
|
|
|
test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
|
2009-01-16 16:00:02 +08:00
|
|
|
|
2009-04-12 11:41:56 +08:00
|
|
|
if test -z "$merge_tool"; then
|
|
|
|
merge_tool="$(get_merge_tool)" || exit
|
|
|
|
fi
|
2009-01-16 16:00:02 +08:00
|
|
|
|
|
|
|
# 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
|