git-diff.shon commit builtin-push: make it official. (54eb2d3)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4# Copyright (c) 2005 Junio C Hamano
   5
   6USAGE='[ --diff-options ] <ent>{0,2} [<path>...]'
   7SUBDIRECTORY_OK='Yes'
   8. git-sh-setup
   9
  10rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
  11flags=$(git-rev-parse --no-revs --flags --sq "$@")
  12files=$(git-rev-parse --no-revs --no-flags --sq "$@")
  13
  14# I often say 'git diff --cached -p' and get scolded by git-diff-files, but
  15# obviously I mean 'git diff --cached -p HEAD' in that case.
  16case "$rev" in
  17'')
  18        case " $flags " in
  19        *" '--cached' "*)
  20                rev='HEAD '
  21                ;;
  22        esac
  23esac
  24
  25# If we have -[123] --ours --theirs --base, don't do --cc by default.
  26case " $flags " in
  27*" '-"[123]"' "* | *" '--ours' "* | *" '--base' "* | *" '--theirs' "*)
  28        cc_or_p=-p ;;
  29*)
  30        cc_or_p=--cc ;;
  31esac
  32
  33# If we do not have --name-status, --name-only, -r, -c or --stat,
  34# default to --cc.
  35case " $flags " in
  36*" '--name-status' "* | *" '--name-only' "* | *" '-r' "* | *" '-c' "* | \
  37*" '--stat' "*)
  38        ;;
  39*)
  40        flags="$flags'$cc_or_p' " ;;
  41esac
  42
  43# If we do not have -B, -C, -r, nor -p, default to -M.
  44case " $flags " in
  45*" '-"[BCMrp]* | *" '--find-copies-harder' "*)
  46        ;; # something like -M50.
  47*)
  48        flags="$flags'-M' " ;;
  49esac
  50
  51case "$rev" in
  52?*' '?*' '?*)
  53        usage
  54        ;;
  55?*' '^?*)
  56        begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
  57        end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
  58        cmd="git-diff-tree $flags $begin $end -- $files"
  59        ;;
  60?*' '?*)
  61        cmd="git-diff-tree $flags $rev -- $files"
  62        ;;
  63?*' ')
  64        cmd="git-diff-index $flags $rev -- $files"
  65        ;;
  66'')
  67        cmd="git-diff-files $flags -- $files"
  68        ;;
  69*)
  70        usage
  71        ;;
  72esac
  73
  74eval "$cmd"