New tutorial
[git/trast.git] / git-diff.sh
blob4812ae4c1ff937ded49334a97ee1dc2c1732e433
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 do not have --name-status, --name-only nor -r, default to -p.
26 # If we do not have -B nor -C, default to -M.
27 case " $flags " in
28 *" '--name-status' "* | *" '--name-only' "* | *" '-r' "* )
31 flags="$flags'-p' " ;;
32 esac
33 case " $flags " in
34 *" '-"[BCM]* | *" '--find-copies-harder' "*)
35 ;; # something like -M50.
37 flags="$flags'-M' " ;;
38 esac
40 case "$rev" in
41 ?*' '?*' '?*)
42 usage
44 ?*' '^?*)
45 begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
46 end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
47 cmd="git-diff-tree $flags $begin $end -- $files"
49 ?*' '?*)
50 cmd="git-diff-tree $flags $rev -- $files"
52 ?*' ')
53 cmd="git-diff-index $flags $rev -- $files"
55 '')
56 cmd="git-diff-files $flags -- $files"
59 usage
61 esac
63 eval "$cmd"