merge-one-file: leave unmerged index entries upon automerge failure.
[git/jnareb-git.git] / git-diff.sh
blob7baf7044e440e6d052f5e92e1008f710dd319c67
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
6 rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
7 flags=$(git-rev-parse --no-revs --flags --sq "$@")
8 files=$(git-rev-parse --no-revs --no-flags --sq "$@")
10 # I often say 'git diff --cached -p' and get scolded by git-diff-files, but
11 # obviously I mean 'git diff --cached -p HEAD' in that case.
12 case "$rev" in
13 '')
14 case " $flags " in
15 *" '--cached' "*)
16 rev='HEAD '
18 esac
19 esac
21 # If we do not have --name-status, --name-only nor -r, default to -p.
22 # If we do not have -B nor -C, default to -M.
23 case " $flags " in
24 *" '--name-status' "* | *" '--name-only' "* | *" '-r' "* )
27 flags="$flags'-p' " ;;
28 esac
29 case " $flags " in
30 *" '-"[BCM]* | *" '--find-copies-harder' "*)
31 ;; # something like -M50.
33 flags="$flags'-M' " ;;
34 esac
36 case "$rev" in
37 ?*' '?*' '?*)
38 echo >&2 "I don't understand"
39 exit 1
41 ?*' '^?*)
42 begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
43 end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
44 cmd="git-diff-tree $flags $begin $end -- $files"
46 ?*' '?*)
47 cmd="git-diff-tree $flags $rev -- $files"
49 ?*' ')
50 cmd="git-diff-index $flags $rev -- $files"
52 '')
53 cmd="git-diff-files $flags -- $files"
56 die "I don't understand $*"
58 esac
60 eval "$cmd"