git-difftool--helper.shon commit gitweb: Incremental blame (using JavaScript) (4af819d)
   1#!/bin/sh
   2# git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
   3# This script is typically launched by using the 'git difftool'
   4# convenience command.
   5#
   6# Copyright (c) 2009 David Aguilar
   7
   8# Load common functions from git-mergetool--lib
   9TOOL_MODE=diff
  10. git-mergetool--lib
  11
  12# difftool.prompt controls the default prompt/no-prompt behavior
  13# and is overridden with $GIT_DIFFTOOL*_PROMPT.
  14should_prompt () {
  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
  21}
  22
  23# Sets up shell variables and runs a merge tool
  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"
  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
  43        run_merge_tool "$merge_tool"
  44}
  45
  46# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
  47test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
  48test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
  49
  50if test -z "$merge_tool"; then
  51        merge_tool="$(get_merge_tool)" || exit
  52fi
  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