summaryrefslogtreecommitdiff
path: root/git-difftool--helper.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-04-18 04:42:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-04-18 04:42:12 (GMT)
commitbd15ef078afac3f0f147e815d3b85d6d2a48dd1a (patch)
treeb009b23ff8114f1c50e2dff0d664d8d7926d0472 /git-difftool--helper.sh
parent2d430c713372fc21f9acf1d8b745e7f4fbbe336c (diff)
parent47d65924a69576bd9f3254f7055de6b37a359596 (diff)
downloadgit-bd15ef078afac3f0f147e815d3b85d6d2a48dd1a.zip
git-bd15ef078afac3f0f147e815d3b85d6d2a48dd1a.tar.gz
git-bd15ef078afac3f0f147e815d3b85d6d2a48dd1a.tar.bz2
Merge branch 'da/difftool'
* da/difftool: mergetool--lib: simplify API usage by removing more global variables Fix misspelled mergetool.keepBackup difftool/mergetool: refactor commands to use git-mergetool--lib mergetool: use $( ... ) instead of `backticks` bash completion: add git-difftool difftool: add support for a difftool.prompt config variable difftool: add various git-difftool tests difftool: move 'git-difftool' out of contrib difftool/mergetool: add diffuse as merge and diff tool difftool: add a -y shortcut for --no-prompt difftool: use perl built-ins when testing for msys difftool: remove the backup file feature difftool: remove merge options for opendiff, tkdiff, kdiff3 and xxdiff git-mergetool: add new merge tool TortoiseMerge git-mergetool/difftool: make (g)vimdiff workable under Windows doc/merge-config: list ecmerge as a built-in merge tool
Diffstat (limited to 'git-difftool--helper.sh')
-rwxr-xr-xgit-difftool--helper.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
new file mode 100755
index 0000000..57e8e32
--- /dev/null
+++ b/git-difftool--helper.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
+# This script is typically launched by using the 'git difftool'
+# convenience command.
+#
+# Copyright (c) 2009 David Aguilar
+
+# Load common functions from git-mergetool--lib
+TOOL_MODE=diff
+. git-mergetool--lib
+
+# difftool.prompt controls the default prompt/no-prompt behavior
+# and is overridden with $GIT_DIFFTOOL*_PROMPT.
+should_prompt () {
+ 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
+}
+
+# Sets up shell variables and runs a merge tool
+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
+ run_merge_tool "$merge_tool"
+}
+
+# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
+test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
+test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
+
+if test -z "$merge_tool"; then
+ merge_tool="$(get_merge_tool)" || exit
+fi
+
+# 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