Teach "git diff" to handle filenames starting with '-'
[git/git.git] / git-diff.sh
CommitLineData
940c1bb0 1#!/bin/sh
0a5a9ea4
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4# Copyright (c) 2005 Junio C Hamano
5
6rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
7flags=$(git-rev-parse --no-revs --flags --sq "$@")
8files=$(git-rev-parse --no-revs --no-flags --sq "$@")
9
10: ${flags:="'-M' '-p'"}
11
9f92f15f
JH
12# I often say 'git diff --cached -p' and get scolded by git-diff-files, but
13# obviously I mean 'git diff --cached -p HEAD' in that case.
14case "$rev" in
15'')
16 case " $flags " in
17 *" '--cached' "*)
18 rev='HEAD '
19 ;;
20 esac
21esac
22
0a5a9ea4
JH
23case "$rev" in
24?*' '?*' '?*)
9f92f15f
JH
25 echo >&2 "I don't understand"
26 exit 1
0a5a9ea4
JH
27 ;;
28?*' '^?*)
29 begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
30 end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
ea51d416 31 cmd="git-diff-tree $flags $begin $end -- $files"
0a5a9ea4
JH
32 ;;
33?*' '?*)
ea51d416 34 cmd="git-diff-tree $flags $rev -- $files"
0a5a9ea4
JH
35 ;;
36?*' ')
ea51d416 37 cmd="git-diff-index $flags $rev -- $files"
0a5a9ea4
JH
38 ;;
39'')
ea51d416 40 cmd="git-diff-files $flags -- $files"
0a5a9ea4 41 ;;
940c1bb0 42*)
0a5a9ea4
JH
43 die "I don't understand $*"
44 ;;
940c1bb0 45esac
0a5a9ea4
JH
46
47eval "$cmd"