]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4027-diff-submodule.sh
t3905: move all commands into test cases
[thirdparty/git.git] / t / t4027-diff-submodule.sh
CommitLineData
2b459b48
JH
1#!/bin/sh
2
3test_description='difference in submodules'
4
5. ./test-lib.sh
bfdbee98 6. "$TEST_DIRECTORY"/diff-lib.sh
2b459b48 7
2b459b48
JH
8test_expect_success setup '
9 test_tick &&
10 test_create_repo sub &&
11 (
12 cd sub &&
13 echo hello >world &&
14 git add world &&
15 git commit -m submodule
16 ) &&
17
18 test_tick &&
19 echo frotz >nitfol &&
20 git add nitfol sub &&
21 git commit -m superproject &&
22
23 (
24 cd sub &&
25 echo goodbye >world &&
26 git add world &&
27 git commit -m "submodule #2"
28 ) &&
29
30 set x $(
31 cd sub &&
32 git rev-list HEAD
33 ) &&
8125a58b 34 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
8e08b419 35 subtip=$3 subprev=$2
2b459b48
JH
36'
37
38test_expect_success 'git diff --raw HEAD' '
45e2ef2b 39 hexsz=$(test_oid hexsz) &&
40 git diff --raw --abbrev=$hexsz HEAD >actual &&
82ebb0b6 41 test_cmp expect actual
2b459b48
JH
42'
43
44test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
82ebb0b6 46 test_cmp expect actual.index
2b459b48
JH
47'
48
49test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
82ebb0b6 51 test_cmp expect actual.files
2b459b48
JH
52'
53
8e08b419
JH
54expect_from_to () {
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
56 "-" "$1" "$2"
57}
58
59test_expect_success 'git diff HEAD' '
60 git diff HEAD >actual &&
61 sed -e "1,/^@@/d" actual >actual.body &&
62 expect_from_to >expect.body $subtip $subprev &&
63 test_cmp expect.body actual.body
64'
65
66test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
67 echo >>sub/world &&
68 git diff HEAD >actual &&
69 sed -e "1,/^@@/d" actual >actual.body &&
70 expect_from_to >expect.body $subtip $subprev-dirty &&
71 test_cmp expect.body actual.body
72'
73
74test_expect_success 'git diff HEAD with dirty submodule (index)' '
75 (
76 cd sub &&
77 git reset --hard &&
78 echo >>world &&
79 git add world
80 ) &&
81 git diff HEAD >actual &&
82 sed -e "1,/^@@/d" actual >actual.body &&
83 expect_from_to >expect.body $subtip $subprev-dirty &&
84 test_cmp expect.body actual.body
85'
86
87test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
88 (
89 cd sub &&
90 git reset --hard &&
91 git clean -qfdx &&
92 >cruft
93 ) &&
94 git diff HEAD >actual &&
95 sed -e "1,/^@@/d" actual >actual.body &&
8ef93124
SJ
96 expect_from_to >expect.body $subtip $subprev &&
97 test_cmp expect.body actual.body
98'
99
100test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
101 test_config diff.ignoreSubmodules none &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
8e08b419
JH
104 expect_from_to >expect.body $subtip $subprev-dirty &&
105 test_cmp expect.body actual.body
106'
107
108test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
109 git commit -m "x" sub &&
110 echo >>sub/world &&
111 git diff HEAD >actual &&
112 sed -e "1,/^@@/d" actual >actual.body &&
113 expect_from_to >expect.body $subprev $subprev-dirty &&
dd44d419
JL
114 test_cmp expect.body actual.body &&
115 git diff --ignore-submodules HEAD >actual2 &&
ec10b018 116 test_must_be_empty actual2 &&
dd44d419
JL
117 git diff --ignore-submodules=untracked HEAD >actual3 &&
118 sed -e "1,/^@@/d" actual3 >actual3.body &&
119 expect_from_to >expect.body $subprev $subprev-dirty &&
120 test_cmp expect.body actual3.body &&
121 git diff --ignore-submodules=dirty HEAD >actual4 &&
ec10b018 122 test_must_be_empty actual4
8e08b419 123'
6ed7ddaa 124
302ad7a9 125test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
90e14525
JL
126 git config diff.ignoreSubmodules dirty &&
127 git diff HEAD >actual &&
ec10b018 128 test_must_be_empty actual &&
302ad7a9
JL
129 git config --add -f .gitmodules submodule.subname.ignore none &&
130 git config --add -f .gitmodules submodule.subname.path sub &&
131 git diff HEAD >actual &&
132 sed -e "1,/^@@/d" actual >actual.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual.body &&
135 git config -f .gitmodules submodule.subname.ignore all &&
136 git config -f .gitmodules submodule.subname.path sub &&
137 git diff HEAD >actual2 &&
ec10b018 138 test_must_be_empty actual2 &&
302ad7a9
JL
139 git config -f .gitmodules submodule.subname.ignore untracked &&
140 git diff HEAD >actual3 &&
141 sed -e "1,/^@@/d" actual3 >actual3.body &&
142 expect_from_to >expect.body $subprev $subprev-dirty &&
143 test_cmp expect.body actual3.body &&
144 git config -f .gitmodules submodule.subname.ignore dirty &&
145 git diff HEAD >actual4 &&
ec10b018 146 test_must_be_empty actual4 &&
302ad7a9
JL
147 git config submodule.subname.ignore none &&
148 git config submodule.subname.path sub &&
149 git diff HEAD >actual &&
150 sed -e "1,/^@@/d" actual >actual.body &&
151 expect_from_to >expect.body $subprev $subprev-dirty &&
152 test_cmp expect.body actual.body &&
153 git config --remove-section submodule.subname &&
154 git config --remove-section -f .gitmodules submodule.subname &&
90e14525 155 git config --unset diff.ignoreSubmodules &&
302ad7a9
JL
156 rm .gitmodules
157'
158
8e08b419
JH
159test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
160 (
161 cd sub &&
162 git reset --hard &&
163 echo >>world &&
164 git add world
165 ) &&
166 git diff HEAD >actual &&
167 sed -e "1,/^@@/d" actual >actual.body &&
168 expect_from_to >expect.body $subprev $subprev-dirty &&
169 test_cmp expect.body actual.body
170'
171
172test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
173 (
174 cd sub &&
175 git reset --hard &&
176 git clean -qfdx &&
177 >cruft
178 ) &&
8ef93124 179 git diff --ignore-submodules=none HEAD >actual &&
8e08b419
JH
180 sed -e "1,/^@@/d" actual >actual.body &&
181 expect_from_to >expect.body $subprev $subprev-dirty &&
dd44d419
JL
182 test_cmp expect.body actual.body &&
183 git diff --ignore-submodules=all HEAD >actual2 &&
ec10b018 184 test_must_be_empty actual2 &&
8ef93124 185 git diff HEAD >actual3 &&
ec10b018 186 test_must_be_empty actual3 &&
dd44d419 187 git diff --ignore-submodules=dirty HEAD >actual4 &&
ec10b018 188 test_must_be_empty actual4
8e08b419
JH
189'
190
302ad7a9
JL
191test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
192 git config --add -f .gitmodules submodule.subname.ignore all &&
193 git config --add -f .gitmodules submodule.subname.path sub &&
194 git diff HEAD >actual2 &&
ec10b018 195 test_must_be_empty actual2 &&
302ad7a9
JL
196 git config -f .gitmodules submodule.subname.ignore untracked &&
197 git diff HEAD >actual3 &&
ec10b018 198 test_must_be_empty actual3 &&
302ad7a9
JL
199 git config -f .gitmodules submodule.subname.ignore dirty &&
200 git diff HEAD >actual4 &&
ec10b018 201 test_must_be_empty actual4 &&
302ad7a9
JL
202 git config submodule.subname.ignore none &&
203 git config submodule.subname.path sub &&
204 git diff HEAD >actual &&
205 sed -e "1,/^@@/d" actual >actual.body &&
206 expect_from_to >expect.body $subprev $subprev-dirty &&
207 test_cmp expect.body actual.body &&
208 git config --remove-section submodule.subname &&
209 git config --remove-section -f .gitmodules submodule.subname &&
210 rm .gitmodules
211'
212
aee9c7d6
JL
213test_expect_success 'git diff between submodule commits' '
214 git diff HEAD^..HEAD >actual &&
215 sed -e "1,/^@@/d" actual >actual.body &&
216 expect_from_to >expect.body $subtip $subprev &&
217 test_cmp expect.body actual.body &&
218 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
219 sed -e "1,/^@@/d" actual >actual.body &&
220 expect_from_to >expect.body $subtip $subprev &&
221 test_cmp expect.body actual.body &&
222 git diff --ignore-submodules HEAD^..HEAD >actual &&
ec10b018 223 test_must_be_empty actual
aee9c7d6
JL
224'
225
302ad7a9
JL
226test_expect_success 'git diff between submodule commits [.gitmodules]' '
227 git diff HEAD^..HEAD >actual &&
228 sed -e "1,/^@@/d" actual >actual.body &&
229 expect_from_to >expect.body $subtip $subprev &&
230 test_cmp expect.body actual.body &&
231 git config --add -f .gitmodules submodule.subname.ignore dirty &&
232 git config --add -f .gitmodules submodule.subname.path sub &&
233 git diff HEAD^..HEAD >actual &&
234 sed -e "1,/^@@/d" actual >actual.body &&
235 expect_from_to >expect.body $subtip $subprev &&
236 test_cmp expect.body actual.body &&
237 git config -f .gitmodules submodule.subname.ignore all &&
238 git diff HEAD^..HEAD >actual &&
ec10b018 239 test_must_be_empty actual &&
302ad7a9
JL
240 git config submodule.subname.ignore dirty &&
241 git config submodule.subname.path sub &&
242 git diff HEAD^..HEAD >actual &&
243 sed -e "1,/^@@/d" actual >actual.body &&
244 expect_from_to >expect.body $subtip $subprev &&
245 git config --remove-section submodule.subname &&
246 git config --remove-section -f .gitmodules submodule.subname &&
247 rm .gitmodules
248'
249
1392a377 250test_expect_success 'git diff (empty submodule dir)' '
7c08a2a6
PY
251 rm -rf sub/* sub/.git &&
252 git diff > actual.empty &&
1c5e94f4 253 test_must_be_empty actual.empty
7c08a2a6
PY
254'
255
7dae8b21 256test_expect_success 'conflicted submodule setup' '
45e2ef2b 257 c=$(test_oid ff_1) &&
7dae8b21 258 (
8125a58b 259 echo "000000 $ZERO_OID 0 sub" &&
a48fcd83
JN
260 echo "160000 1$c 1 sub" &&
261 echo "160000 2$c 2 sub" &&
7dae8b21
JH
262 echo "160000 3$c 3 sub"
263 ) | git update-index --index-info &&
45e2ef2b 264 echo >expect.nosub "diff --cc sub
7dae8b21
JH
265index 2ffffff,3ffffff..0000000
266--- a/sub
267+++ b/sub
268@@@ -1,1 -1,1 +1,1 @@@
45e2ef2b 269- Subproject commit 2$c
270 -Subproject commit 3$c
271++Subproject commit $ZERO_OID" &&
7dae8b21
JH
272
273 hh=$(git rev-parse HEAD) &&
8125a58b 274 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
7dae8b21
JH
275
276'
277
278test_expect_success 'combined (empty submodule)' '
279 rm -fr sub && mkdir sub &&
280 git diff >actual &&
281 test_cmp expect.nosub actual
282'
283
284test_expect_success 'combined (with submodule)' '
285 rm -fr sub &&
286 git clone --no-checkout . sub &&
287 git diff >actual &&
288 test_cmp expect.withsub actual
289'
290
291
292
2b459b48 293test_done