Merge branch 'rb/maint-python-path' into maint
[git/debian.git] / t / t4017-diff-retval.sh
blob0391a5827ea8ba196b7796b7df818f8ac860c387
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
124 test_expect_success 'check should test not just the last line' '
125 echo "" >>a &&
126 git --no-pager diff --check
127 test $? = 2
131 test_expect_success 'check detects leftover conflict markers' '
132 git reset --hard &&
133 git checkout HEAD^ &&
134 echo binary >>b &&
135 git commit -m "side" b &&
136 test_must_fail git merge master &&
137 git add b && (
138 git --no-pager diff --cached --check >test.out
139 test $? = 2
140 ) &&
141 test 3 = $(grep "conflict marker" test.out | wc -l) &&
142 git reset --hard
145 test_done