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