Fix handling of git-p4 on deleted files
[git/kirr.git] / t / t4017-diff-retval.sh
blob61589853df55e063fbe6489fc9c6effc4a9f33b6
1 #!/bin/sh
3 test_description='Return value of diffs'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 echo "1 " >a &&
9 git add . &&
10 git commit -m zeroth &&
11 echo 1 >a &&
12 git add . &&
13 git commit -m first &&
14 echo 2 >b &&
15 git add . &&
16 git commit -a -m second
19 test_expect_success 'git diff --quiet -w HEAD^^ HEAD^' '
20 git diff --quiet -w HEAD^^ HEAD^
23 test_expect_success 'git diff --quiet HEAD^^ HEAD^' '
24 test_must_fail git diff --quiet HEAD^^ HEAD^
27 test_expect_success 'git diff --quiet -w HEAD^ HEAD' '
28 test_must_fail git diff --quiet -w HEAD^ HEAD
31 test_expect_success 'git diff-tree HEAD^ HEAD' '
32 git diff-tree --exit-code HEAD^ HEAD
33 test $? = 1
35 test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
36 git diff-tree --exit-code HEAD^ HEAD -- a
37 test $? = 0
39 test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
40 git diff-tree --exit-code HEAD^ HEAD -- b
41 test $? = 1
43 test_expect_success 'echo HEAD | git diff-tree --stdin' '
44 echo $(git rev-parse HEAD) | git diff-tree --exit-code --stdin
45 test $? = 1
47 test_expect_success 'git diff-tree HEAD HEAD' '
48 git diff-tree --exit-code HEAD HEAD
49 test $? = 0
51 test_expect_success 'git diff-files' '
52 git diff-files --exit-code
53 test $? = 0
55 test_expect_success 'git diff-index --cached HEAD' '
56 git diff-index --exit-code --cached HEAD
57 test $? = 0
59 test_expect_success 'git diff-index --cached HEAD^' '
60 git diff-index --exit-code --cached HEAD^
61 test $? = 1
63 test_expect_success 'git diff-index --cached HEAD^' '
64 echo text >>b &&
65 echo 3 >c &&
66 git add . && {
67 git diff-index --exit-code --cached HEAD^
68 test $? = 1
71 test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
72 git commit -m "text in b" && {
73 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
74 test $? = 1
77 test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
78 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
79 test $? = 0
81 test_expect_success 'git diff-files' '
82 echo 3 >>c && {
83 git diff-files --exit-code
84 test $? = 1
87 test_expect_success 'git diff-index --cached HEAD' '
88 git update-index c && {
89 git diff-index --exit-code --cached HEAD
90 test $? = 1
94 test_expect_success '--check --exit-code returns 0 for no difference' '
96 git diff --check --exit-code
100 test_expect_success '--check --exit-code returns 1 for a clean difference' '
102 echo "good" > a &&
103 git diff --check --exit-code
104 test $? = 1
108 test_expect_success '--check --exit-code returns 3 for a dirty difference' '
110 echo "bad " >> a &&
111 git diff --check --exit-code
112 test $? = 3
116 test_expect_success '--check with --no-pager returns 2 for dirty difference' '
118 git --no-pager diff --check
119 test $? = 2
123 test_expect_success 'check should test not just the last line' '
124 echo "" >>a &&
125 git --no-pager diff --check
126 test $? = 2
130 test_expect_success 'check detects leftover conflict markers' '
131 git reset --hard &&
132 git checkout HEAD^ &&
133 echo binary >>b &&
134 git commit -m "side" b &&
135 test_must_fail git merge master &&
136 git add b && (
137 git --no-pager diff --cached --check >test.out
138 test $? = 2
139 ) &&
140 test 3 = $(grep "conflict marker" test.out | wc -l) &&
141 git reset --hard
144 test_expect_success 'check honors conflict marker length' '
145 git reset --hard &&
146 echo ">>>>>>> boo" >>b &&
147 echo "======" >>a &&
148 git diff --check a &&
150 git diff --check b
151 test $? = 2
152 ) &&
153 git reset --hard &&
154 echo ">>>>>>>> boo" >>b &&
155 echo "========" >>a &&
156 git diff --check &&
157 echo "b conflict-marker-size=8" >.gitattributes &&
159 git diff --check b
160 test $? = 2
161 ) &&
162 git diff --check a &&
163 git reset --hard
166 test_done