]>
Commit | Line | Data |
---|---|---|
41bbf9d5 AR |
1 | #!/bin/sh |
2 | ||
3 | test_description='Return value of diffs' | |
4 | ||
8f37854b | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
3e3b9321 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
41bbf9d5 AR |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success 'setup' ' | |
1caaf225 LA |
12 | echo "1 " >a && |
13 | git add . && | |
14 | git commit -m zeroth && | |
41bbf9d5 AR |
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 | |
21 | ' | |
22 | ||
1caaf225 LA |
23 | test_expect_success 'git diff --quiet -w HEAD^^ HEAD^' ' |
24 | git diff --quiet -w HEAD^^ HEAD^ | |
25 | ' | |
26 | ||
27 | test_expect_success 'git diff --quiet HEAD^^ HEAD^' ' | |
28 | test_must_fail git diff --quiet HEAD^^ HEAD^ | |
29 | ' | |
30 | ||
31 | test_expect_success 'git diff --quiet -w HEAD^ HEAD' ' | |
32 | test_must_fail git diff --quiet -w HEAD^ HEAD | |
33 | ' | |
34 | ||
41bbf9d5 | 35 | test_expect_success 'git diff-tree HEAD^ HEAD' ' |
dd0c69e9 | 36 | test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD |
41bbf9d5 AR |
37 | ' |
38 | test_expect_success 'git diff-tree HEAD^ HEAD -- a' ' | |
39 | git diff-tree --exit-code HEAD^ HEAD -- a | |
41bbf9d5 AR |
40 | ' |
41 | test_expect_success 'git diff-tree HEAD^ HEAD -- b' ' | |
dd0c69e9 | 42 | test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b |
41bbf9d5 AR |
43 | ' |
44 | test_expect_success 'echo HEAD | git diff-tree --stdin' ' | |
dd0c69e9 | 45 | echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin |
41bbf9d5 AR |
46 | ' |
47 | test_expect_success 'git diff-tree HEAD HEAD' ' | |
48 | git diff-tree --exit-code HEAD HEAD | |
41bbf9d5 AR |
49 | ' |
50 | test_expect_success 'git diff-files' ' | |
51 | git diff-files --exit-code | |
41bbf9d5 AR |
52 | ' |
53 | test_expect_success 'git diff-index --cached HEAD' ' | |
54 | git diff-index --exit-code --cached HEAD | |
41bbf9d5 AR |
55 | ' |
56 | test_expect_success 'git diff-index --cached HEAD^' ' | |
dd0c69e9 | 57 | test_expect_code 1 git diff-index --exit-code --cached HEAD^ |
41bbf9d5 AR |
58 | ' |
59 | test_expect_success 'git diff-index --cached HEAD^' ' | |
60 | echo text >>b && | |
61 | echo 3 >c && | |
dd0c69e9 EN |
62 | git add . && |
63 | test_expect_code 1 git diff-index --exit-code --cached HEAD^ | |
41bbf9d5 AR |
64 | ' |
65 | test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' ' | |
dd0c69e9 EN |
66 | git commit -m "text in b" && |
67 | test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b | |
41bbf9d5 AR |
68 | ' |
69 | test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' ' | |
70 | git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b | |
41bbf9d5 AR |
71 | ' |
72 | test_expect_success 'git diff-files' ' | |
dd0c69e9 EN |
73 | echo 3 >>c && |
74 | test_expect_code 1 git diff-files --exit-code | |
41bbf9d5 AR |
75 | ' |
76 | test_expect_success 'git diff-index --cached HEAD' ' | |
dd0c69e9 EN |
77 | git update-index c && |
78 | test_expect_code 1 git diff-index --exit-code --cached HEAD | |
41bbf9d5 AR |
79 | ' |
80 | ||
5973a079 WC |
81 | test_expect_success '--check --exit-code returns 0 for no difference' ' |
82 | ||
83 | git diff --check --exit-code | |
84 | ||
85 | ' | |
86 | ||
87 | test_expect_success '--check --exit-code returns 1 for a clean difference' ' | |
88 | ||
89 | echo "good" > a && | |
dd0c69e9 | 90 | test_expect_code 1 git diff --check --exit-code |
5973a079 WC |
91 | |
92 | ' | |
93 | ||
94 | test_expect_success '--check --exit-code returns 3 for a dirty difference' ' | |
95 | ||
96 | echo "bad " >> a && | |
dd0c69e9 | 97 | test_expect_code 3 git diff --check --exit-code |
5973a079 WC |
98 | |
99 | ' | |
100 | ||
101 | test_expect_success '--check with --no-pager returns 2 for dirty difference' ' | |
102 | ||
dd0c69e9 | 103 | test_expect_code 2 git --no-pager diff --check |
5973a079 WC |
104 | |
105 | ' | |
106 | ||
18374e58 JH |
107 | test_expect_success 'check should test not just the last line' ' |
108 | echo "" >>a && | |
dd0c69e9 | 109 | test_expect_code 2 git --no-pager diff --check |
18374e58 JH |
110 | |
111 | ' | |
112 | ||
04954043 JH |
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 && | |
8f37854b | 118 | test_must_fail git merge main && |
dd0c69e9 EN |
119 | git add b && |
120 | test_expect_code 2 git --no-pager diff --cached --check >test.out && | |
ab20fda9 | 121 | test 3 = $(grep "conflict marker" test.out | wc -l) && |
04954043 JH |
122 | git reset --hard |
123 | ' | |
124 | ||
a757c646 JH |
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 && | |
dd0c69e9 | 130 | test_expect_code 2 git diff --check b && |
a757c646 JH |
131 | git reset --hard && |
132 | echo ">>>>>>>> boo" >>b && | |
133 | echo "========" >>a && | |
134 | git diff --check && | |
135 | echo "b conflict-marker-size=8" >.gitattributes && | |
dd0c69e9 | 136 | test_expect_code 2 git diff --check b && |
a757c646 JH |
137 | git diff --check a && |
138 | git reset --hard | |
139 | ' | |
140 | ||
5ad6e2b4 JK |
141 | test_expect_success 'option errors are not confused by --exit-code' ' |
142 | test_must_fail git diff --exit-code --nonsense 2>err && | |
143 | grep '^usage:' err | |
144 | ' | |
145 | ||
41bbf9d5 | 146 | test_done |