Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 60 lines (51 sloc) 1.632 kb
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
1 #!/bin/sh
afcbc8e @davvid difftool: move 'git-difftool' out of contrib
davvid authored
2 # git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
3 # This script is typically launched by using the 'git difftool'
4 # convenience command.
5 #
6 # Copyright (c) 2009 David Aguilar
7
21d0ba7 @davvid difftool/mergetool: refactor commands to use git-mergetool--lib
davvid authored
8 # Load common functions from git-mergetool--lib
9 TOOL_MODE=diff
10 . git-mergetool--lib
11
a904392 @davvid difftool: add support for a difftool.prompt config variable
davvid authored
12 # difftool.prompt controls the default prompt/no-prompt behavior
13 # and is overridden with $GIT_DIFFTOOL*_PROMPT.
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
14 should_prompt () {
a904392 @davvid difftool: add support for a difftool.prompt config variable
davvid authored
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
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
21 }
22
21d0ba7 @davvid difftool/mergetool: refactor commands to use git-mergetool--lib
davvid authored
23 # Sets up shell variables and runs a merge tool
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
24 launch_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"
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
21d0ba7 @davvid difftool/mergetool: refactor commands to use git-mergetool--lib
davvid authored
43 run_merge_tool "$merge_tool"
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
44 }
45
2464456 @davvid contrib/difftool: use a separate config namespace for difftool commands
davvid authored
46 # Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
47 test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
2464456 @davvid contrib/difftool: use a separate config namespace for difftool commands
davvid authored
48 test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
49
47d6592 @davvid mergetool--lib: simplify API usage by removing more global variables
davvid authored
50 if test -z "$merge_tool"; then
51 merge_tool="$(get_merge_tool)" || exit
52 fi
5c38ea3 @davvid contrib: add 'git difftool' for launching common merge tools
davvid authored
53
54 # Launch the merge tool on each path provided by 'git diff'
55 while test $# -gt 6
56 do
57 launch_merge_tool "$1" "$2" "$5"
58 shift 7
59 done
Something went wrong with that request. Please try again.