3 test_description
='Return value of diffs'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'setup' '
13 git commit -m zeroth &&
16 git commit -m first &&
19 git commit -a -m second
22 test_expect_success
'git diff --quiet -w HEAD^^ HEAD^' '
23 git diff --quiet -w HEAD^^ HEAD^
26 test_expect_success
'git diff --quiet HEAD^^ HEAD^' '
27 test_must_fail git diff --quiet HEAD^^ HEAD^
30 test_expect_success
'git diff --quiet -w HEAD^ HEAD' '
31 test_must_fail git diff --quiet -w HEAD^ HEAD
34 test_expect_success
'git diff-tree HEAD^ HEAD' '
35 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
37 test_expect_success
'git diff-tree HEAD^ HEAD -- a' '
38 git diff-tree --exit-code HEAD^ HEAD -- a
40 test_expect_success
'git diff-tree HEAD^ HEAD -- b' '
41 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b
43 test_expect_success
'echo HEAD | git diff-tree --stdin' '
44 echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin
46 test_expect_success
'git diff-tree HEAD HEAD' '
47 git diff-tree --exit-code HEAD HEAD
49 test_expect_success
'git diff-files' '
50 git diff-files --exit-code
52 test_expect_success
'git diff-index --cached HEAD' '
53 git diff-index --exit-code --cached HEAD
55 test_expect_success
'git diff-index --cached HEAD^' '
56 test_expect_code 1 git diff-index --exit-code --cached HEAD^
58 test_expect_success
'git diff-index --cached HEAD^' '
62 test_expect_code 1 git diff-index --exit-code --cached HEAD^
64 test_expect_success
'git diff-tree -Stext HEAD^ HEAD -- b' '
65 git commit -m "text in b" &&
66 test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
68 test_expect_success
'git diff-tree -Snot-found HEAD^ HEAD -- b' '
69 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
71 test_expect_success
'git diff-files' '
73 test_expect_code 1 git diff-files --exit-code
75 test_expect_success
'git diff-index --cached HEAD' '
77 test_expect_code 1 git diff-index --exit-code --cached HEAD
80 test_expect_success
'--check --exit-code returns 0 for no difference' '
82 git diff --check --exit-code
86 test_expect_success
'--check --exit-code returns 1 for a clean difference' '
89 test_expect_code 1 git diff --check --exit-code
93 test_expect_success
'--check --exit-code returns 3 for a dirty difference' '
96 test_expect_code 3 git diff --check --exit-code
100 test_expect_success
'--check with --no-pager returns 2 for dirty difference' '
102 test_expect_code 2 git --no-pager diff --check
106 test_expect_success
'check should test not just the last line' '
108 test_expect_code 2 git --no-pager diff --check
112 test_expect_success
'check detects leftover conflict markers' '
114 git checkout HEAD^ &&
116 git commit -m "side" b &&
117 test_must_fail git merge main &&
119 test_expect_code 2 git --no-pager diff --cached --check >test.out &&
120 test 3 = $(grep "conflict marker" test.out | wc -l) &&
124 test_expect_success
'check honors conflict marker length' '
126 echo ">>>>>>> boo" >>b &&
128 git diff --check a &&
129 test_expect_code 2 git diff --check b &&
131 echo ">>>>>>>> boo" >>b &&
132 echo "========" >>a &&
134 echo "b conflict-marker-size=8" >.gitattributes &&
135 test_expect_code 2 git diff --check b &&
136 git diff --check a &&