core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t4017-diff-retval.sh
blob95a7ca707045cad3362b92c18df73e82206a2844
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 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
34 test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
35 git diff-tree --exit-code HEAD^ HEAD -- a
37 test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
38 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b
40 test_expect_success 'echo HEAD | git diff-tree --stdin' '
41 echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin
43 test_expect_success 'git diff-tree HEAD HEAD' '
44 git diff-tree --exit-code HEAD HEAD
46 test_expect_success 'git diff-files' '
47 git diff-files --exit-code
49 test_expect_success 'git diff-index --cached HEAD' '
50 git diff-index --exit-code --cached HEAD
52 test_expect_success 'git diff-index --cached HEAD^' '
53 test_expect_code 1 git diff-index --exit-code --cached HEAD^
55 test_expect_success 'git diff-index --cached HEAD^' '
56 echo text >>b &&
57 echo 3 >c &&
58 git add . &&
59 test_expect_code 1 git diff-index --exit-code --cached HEAD^
61 test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
62 git commit -m "text in b" &&
63 test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
65 test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
66 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
68 test_expect_success 'git diff-files' '
69 echo 3 >>c &&
70 test_expect_code 1 git diff-files --exit-code
72 test_expect_success 'git diff-index --cached HEAD' '
73 git update-index c &&
74 test_expect_code 1 git diff-index --exit-code --cached HEAD
77 test_expect_success '--check --exit-code returns 0 for no difference' '
79 git diff --check --exit-code
83 test_expect_success '--check --exit-code returns 1 for a clean difference' '
85 echo "good" > a &&
86 test_expect_code 1 git diff --check --exit-code
90 test_expect_success '--check --exit-code returns 3 for a dirty difference' '
92 echo "bad " >> a &&
93 test_expect_code 3 git diff --check --exit-code
97 test_expect_success '--check with --no-pager returns 2 for dirty difference' '
99 test_expect_code 2 git --no-pager diff --check
103 test_expect_success 'check should test not just the last line' '
104 echo "" >>a &&
105 test_expect_code 2 git --no-pager diff --check
109 test_expect_success 'check detects leftover conflict markers' '
110 git reset --hard &&
111 git checkout HEAD^ &&
112 echo binary >>b &&
113 git commit -m "side" b &&
114 test_must_fail git merge master &&
115 git add b &&
116 test_expect_code 2 git --no-pager diff --cached --check >test.out &&
117 test 3 = $(grep "conflict marker" test.out | wc -l) &&
118 git reset --hard
121 test_expect_success 'check honors conflict marker length' '
122 git reset --hard &&
123 echo ">>>>>>> boo" >>b &&
124 echo "======" >>a &&
125 git diff --check a &&
126 test_expect_code 2 git diff --check b &&
127 git reset --hard &&
128 echo ">>>>>>>> boo" >>b &&
129 echo "========" >>a &&
130 git diff --check &&
131 echo "b conflict-marker-size=8" >.gitattributes &&
132 test_expect_code 2 git diff --check b &&
133 git diff --check a &&
134 git reset --hard
137 test_done