Merge branch 'jc/tree-walk-drop-base-offset'
[git/debian.git] / t / t4017-diff-retval.sh
blob5bc28ad9f042a0476d94d9e90e5b58073cc17f99
1 #!/bin/sh
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
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 echo "1 " >a &&
13 git add . &&
14 git commit -m zeroth &&
15 echo 1 >a &&
16 git add . &&
17 git commit -m first &&
18 echo 2 >b &&
19 git add . &&
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^' '
60 echo text >>b &&
61 echo 3 >c &&
62 git add . &&
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' '
73 echo 3 >>c &&
74 test_expect_code 1 git diff-files --exit-code
76 test_expect_success 'git diff-index --cached HEAD' '
77 git update-index c &&
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' '
89 echo "good" > a &&
90 test_expect_code 1 git diff --check --exit-code
94 test_expect_success '--check --exit-code returns 3 for a dirty difference' '
96 echo "bad " >> a &&
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' '
108 echo "" >>a &&
109 test_expect_code 2 git --no-pager diff --check
113 test_expect_success 'check detects leftover conflict markers' '
114 git reset --hard &&
115 git checkout HEAD^ &&
116 echo binary >>b &&
117 git commit -m "side" b &&
118 test_must_fail git merge main &&
119 git add b &&
120 test_expect_code 2 git --no-pager diff --cached --check >test.out &&
121 test 3 = $(grep "conflict marker" test.out | wc -l) &&
122 git reset --hard
125 test_expect_success 'check honors conflict marker length' '
126 git reset --hard &&
127 echo ">>>>>>> boo" >>b &&
128 echo "======" >>a &&
129 git diff --check a &&
130 test_expect_code 2 git diff --check b &&
131 git reset --hard &&
132 echo ">>>>>>>> boo" >>b &&
133 echo "========" >>a &&
134 git diff --check &&
135 echo "b conflict-marker-size=8" >.gitattributes &&
136 test_expect_code 2 git diff --check b &&
137 git diff --check a &&
138 git reset --hard
141 test_done