GIT v1.3.0-rc4
[git/mingw/4msysgit/kblees.git] / git-diff.sh
blob0fe677074959de444a6c5a273ea816439c6421e0
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
6 USAGE='[ --diff-options ] <ent>{0,2} [<path>...]'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
11 flags=$(git-rev-parse --no-revs --flags --sq "$@")
12 files=$(git-rev-parse --no-revs --no-flags --sq "$@")
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.
16 case "$rev" in
17 '')
18 case " $flags " in
19 *" '--cached' "*)
20 rev='HEAD '
22 esac
23 esac
25 # If we have -[123] --ours --theirs --base, don't do --cc by default.
26 case " $flags " in
27 *" '-"[123]"' "* | *" '--ours' "* | *" '--base' "* | *" '--theirs' "*)
28 cc_or_p=-p ;;
30 cc_or_p=--cc ;;
31 esac
33 # If we do not have --name-status, --name-only, -r, -c or --stat,
34 # default to --cc.
35 case " $flags " in
36 *" '--name-status' "* | *" '--name-only' "* | *" '-r' "* | *" '-c' "* | \
37 *" '--stat' "*)
40 flags="$flags'$cc_or_p' " ;;
41 esac
43 # If we do not have -B, -C, -r, nor -p, default to -M.
44 case " $flags " in
45 *" '-"[BCMrp]* | *" '--find-copies-harder' "*)
46 ;; # something like -M50.
48 flags="$flags'-M' " ;;
49 esac
51 case "$rev" in
52 ?*' '?*' '?*)
53 usage
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"
60 ?*' '?*)
61 cmd="git-diff-tree $flags $rev -- $files"
63 ?*' ')
64 cmd="git-diff-index $flags $rev -- $files"
66 '')
67 cmd="git-diff-files $flags -- $files"
70 usage
72 esac
74 eval "$cmd"