]> git.ipfire.org Git - thirdparty/git.git/blame - git-difftool--helper.sh
Fix some printf format warnings
[thirdparty/git.git] / git-difftool--helper.sh
CommitLineData
5c38ea31 1#!/bin/sh
afcbc8e7 2# git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
5c38ea31
DA
3# This script is typically launched by using the 'git difftool'
4# convenience command.
5#
6# Copyright (c) 2009 David Aguilar
7
21d0ba7e
DA
8# Load common functions from git-mergetool--lib
9TOOL_MODE=diff
10. git-mergetool--lib
11
a904392e
DA
12# difftool.prompt controls the default prompt/no-prompt behavior
13# and is overridden with $GIT_DIFFTOOL*_PROMPT.
5c38ea31 14should_prompt () {
a904392e
DA
15 prompt=$(git config --bool difftool.prompt || echo true)
16 if test "$prompt" = true; then
17 test -z "$GIT_DIFFTOOL_NO_PROMPT"
18 else
19 test -n "$GIT_DIFFTOOL_PROMPT"
20 fi
5c38ea31
DA
21}
22
21d0ba7e 23# Sets up shell variables and runs a merge tool
5c38ea31
DA
24launch_merge_tool () {
25 # Merged is the filename as it appears in the work tree
26 # Local is the contents of a/filename
27 # Remote is the contents of b/filename
28 # Custom merge tool commands might use $BASE so we provide it
29 MERGED="$1"
30 LOCAL="$2"
31 REMOTE="$3"
32 BASE="$1"
5c38ea31
DA
33
34 # $LOCAL and $REMOTE are temporary files so prompt
35 # the user with the real $MERGED name before launching $merge_tool.
36 if should_prompt; then
37 printf "\nViewing: '$MERGED'\n"
38 printf "Hit return to launch '%s': " "$merge_tool"
39 read ans
40 fi
41
42 # Run the appropriate merge tool command
21d0ba7e 43 run_merge_tool "$merge_tool"
5c38ea31
DA
44}
45
2464456a 46# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
5c38ea31 47test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
2464456a 48test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
5c38ea31 49
47d65924
DA
50if test -z "$merge_tool"; then
51 merge_tool="$(get_merge_tool)" || exit
52fi
5c38ea31
DA
53
54# Launch the merge tool on each path provided by 'git diff'
55while test $# -gt 6
56do
57 launch_merge_tool "$1" "$2" "$5"
58 shift 7
59done