3 test_description
='Return value of diffs'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
14 git commit -m zeroth &&
17 git commit -m first &&
20 git commit -a -m second
23 test_expect_success
'git diff --quiet -w HEAD^^ HEAD^' '
24 git diff --quiet -w HEAD^^ HEAD^
27 test_expect_success
'git diff --quiet HEAD^^ HEAD^' '
28 test_must_fail git diff --quiet HEAD^^ HEAD^
31 test_expect_success
'git diff --quiet -w HEAD^ HEAD' '
32 test_must_fail git diff --quiet -w HEAD^ HEAD
35 test_expect_success
'git diff-tree HEAD^ HEAD' '
36 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
38 test_expect_success
'git diff-tree HEAD^ HEAD -- a' '
39 git diff-tree --exit-code HEAD^ HEAD -- a
41 test_expect_success
'git diff-tree HEAD^ HEAD -- b' '
42 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b
44 test_expect_success
'echo HEAD | git diff-tree --stdin' '
45 echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin
47 test_expect_success
'git diff-tree HEAD HEAD' '
48 git diff-tree --exit-code HEAD HEAD
50 test_expect_success
'git diff-files' '
51 git diff-files --exit-code
53 test_expect_success
'git diff-index --cached HEAD' '
54 git diff-index --exit-code --cached HEAD
56 test_expect_success
'git diff-index --cached HEAD^' '
57 test_expect_code 1 git diff-index --exit-code --cached HEAD^
59 test_expect_success
'git diff-index --cached HEAD^' '
63 test_expect_code 1 git diff-index --exit-code --cached HEAD^
65 test_expect_success
'git diff-tree -Stext HEAD^ HEAD -- b' '
66 git commit -m "text in b" &&
67 test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
69 test_expect_success
'git diff-tree -Snot-found HEAD^ HEAD -- b' '
70 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
72 test_expect_success
'git diff-files' '
74 test_expect_code 1 git diff-files --exit-code
76 test_expect_success
'git diff-index --cached HEAD' '
78 test_expect_code 1 git diff-index --exit-code --cached HEAD
81 test_expect_success
'--check --exit-code returns 0 for no difference' '
83 git diff --check --exit-code
87 test_expect_success
'--check --exit-code returns 1 for a clean difference' '
90 test_expect_code 1 git diff --check --exit-code
94 test_expect_success
'--check --exit-code returns 3 for a dirty difference' '
97 test_expect_code 3 git diff --check --exit-code
101 test_expect_success
'--check with --no-pager returns 2 for dirty difference' '
103 test_expect_code 2 git --no-pager diff --check
107 test_expect_success
'check should test not just the last line' '
109 test_expect_code 2 git --no-pager diff --check
113 test_expect_success
'check detects leftover conflict markers' '
115 git checkout HEAD^ &&
117 git commit -m "side" b &&
118 test_must_fail git merge main &&
120 test_expect_code 2 git --no-pager diff --cached --check >test.out &&
121 test 3 = $(grep "conflict marker" test.out | wc -l) &&
125 test_expect_success
'check honors conflict marker length' '
127 echo ">>>>>>> boo" >>b &&
129 git diff --check a &&
130 test_expect_code 2 git diff --check b &&
132 echo ">>>>>>>> boo" >>b &&
133 echo "========" >>a &&
135 echo "b conflict-marker-size=8" >.gitattributes &&
136 test_expect_code 2 git diff --check b &&
137 git diff --check a &&
141 test_expect_success
'option errors are not confused by --exit-code' '
142 test_must_fail git diff --exit-code --nonsense 2>err &&