Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t4017-diff-retval.sh
blobed461f481e2af5e3d73ac628eeee1fb52218d90b
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-lib.sh
10 test_expect_success 'setup' '
11 echo "1 " >a &&
12 git add . &&
13 git commit -m zeroth &&
14 echo 1 >a &&
15 git add . &&
16 git commit -m first &&
17 echo 2 >b &&
18 git add . &&
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^' '
59 echo text >>b &&
60 echo 3 >c &&
61 git add . &&
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' '
72 echo 3 >>c &&
73 test_expect_code 1 git diff-files --exit-code
75 test_expect_success 'git diff-index --cached HEAD' '
76 git update-index c &&
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' '
88 echo "good" > a &&
89 test_expect_code 1 git diff --check --exit-code
93 test_expect_success '--check --exit-code returns 3 for a dirty difference' '
95 echo "bad " >> a &&
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' '
107 echo "" >>a &&
108 test_expect_code 2 git --no-pager diff --check
112 test_expect_success 'check detects leftover conflict markers' '
113 git reset --hard &&
114 git checkout HEAD^ &&
115 echo binary >>b &&
116 git commit -m "side" b &&
117 test_must_fail git merge main &&
118 git add b &&
119 test_expect_code 2 git --no-pager diff --cached --check >test.out &&
120 test 3 = $(grep "conflict marker" test.out | wc -l) &&
121 git reset --hard
124 test_expect_success 'check honors conflict marker length' '
125 git reset --hard &&
126 echo ">>>>>>> boo" >>b &&
127 echo "======" >>a &&
128 git diff --check a &&
129 test_expect_code 2 git diff --check b &&
130 git reset --hard &&
131 echo ">>>>>>>> boo" >>b &&
132 echo "========" >>a &&
133 git diff --check &&
134 echo "b conflict-marker-size=8" >.gitattributes &&
135 test_expect_code 2 git diff --check b &&
136 git diff --check a &&
137 git reset --hard
140 test_done