]>
Commit | Line | Data |
---|---|---|
86140d56 JL |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin | |
4 | # | |
5 | ||
6 | test_description='Support for verbose submodule differences in git diff | |
7 | ||
8 | This test tries to verify the sanity of the --submodule option of git diff. | |
9 | ' | |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
13 | add_file () { | |
14 | sm=$1 | |
15 | shift | |
16 | owd=$(pwd) | |
17 | cd "$sm" | |
18 | for name; do | |
19 | echo "$name" > "$name" && | |
20 | git add "$name" && | |
21 | test_tick && | |
22 | git commit -m "Add $name" | |
23 | done >/dev/null | |
24 | git rev-parse --verify HEAD | cut -c1-7 | |
25 | cd "$owd" | |
26 | } | |
27 | commit_file () { | |
28 | test_tick && | |
29 | git commit "$@" -m "Commit $*" >/dev/null | |
30 | } | |
31 | ||
32 | test_create_repo sm1 && | |
33 | add_file . foo >/dev/null | |
34 | ||
35 | head1=$(add_file sm1 foo1 foo2) | |
36 | ||
37 | test_expect_success 'added submodule' " | |
38 | git add sm1 && | |
39 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 40 | cat >expected <<-EOF && |
86140d56 JL |
41 | Submodule sm1 0000000...$head1 (new submodule) |
42 | EOF | |
f8d186bb | 43 | test_cmp expected actual |
86140d56 JL |
44 | " |
45 | ||
46 | commit_file sm1 && | |
47 | head2=$(add_file sm1 foo3) | |
48 | ||
49 | test_expect_success 'modified submodule(forward)' " | |
50 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 51 | cat >expected <<-EOF && |
86140d56 JL |
52 | Submodule sm1 $head1..$head2: |
53 | > Add foo3 | |
54 | EOF | |
f8d186bb | 55 | test_cmp expected actual |
86140d56 JL |
56 | " |
57 | ||
58 | test_expect_success 'modified submodule(forward)' " | |
59 | git diff --submodule=log >actual && | |
f8d186bb | 60 | cat >expected <<-EOF && |
86140d56 JL |
61 | Submodule sm1 $head1..$head2: |
62 | > Add foo3 | |
63 | EOF | |
f8d186bb | 64 | test_cmp expected actual |
86140d56 JL |
65 | " |
66 | ||
67 | test_expect_success 'modified submodule(forward) --submodule' " | |
68 | git diff --submodule >actual && | |
f8d186bb | 69 | cat >expected <<-EOF && |
86140d56 JL |
70 | Submodule sm1 $head1..$head2: |
71 | > Add foo3 | |
72 | EOF | |
f8d186bb | 73 | test_cmp expected actual |
86140d56 JL |
74 | " |
75 | ||
76 | fullhead1=$(cd sm1; git rev-list --max-count=1 $head1) | |
77 | fullhead2=$(cd sm1; git rev-list --max-count=1 $head2) | |
78 | test_expect_success 'modified submodule(forward) --submodule=short' " | |
79 | git diff --submodule=short >actual && | |
f8d186bb | 80 | cat >expected <<-EOF && |
86140d56 JL |
81 | diff --git a/sm1 b/sm1 |
82 | index $head1..$head2 160000 | |
83 | --- a/sm1 | |
84 | +++ b/sm1 | |
85 | @@ -1 +1 @@ | |
86 | -Subproject commit $fullhead1 | |
87 | +Subproject commit $fullhead2 | |
88 | EOF | |
f8d186bb | 89 | test_cmp expected actual |
86140d56 JL |
90 | " |
91 | ||
92 | commit_file sm1 && | |
18a82692 JN |
93 | head3=$( |
94 | cd sm1 && | |
95 | git reset --hard HEAD~2 >/dev/null && | |
96 | git rev-parse --verify HEAD | cut -c1-7 | |
fd4ec4f2 | 97 | ) |
86140d56 JL |
98 | |
99 | test_expect_success 'modified submodule(backward)' " | |
100 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 101 | cat >expected <<-EOF && |
86140d56 JL |
102 | Submodule sm1 $head2..$head3 (rewind): |
103 | < Add foo3 | |
104 | < Add foo2 | |
105 | EOF | |
f8d186bb | 106 | test_cmp expected actual |
86140d56 JL |
107 | " |
108 | ||
109 | head4=$(add_file sm1 foo4 foo5) && | |
110 | head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD) | |
111 | test_expect_success 'modified submodule(backward and forward)' " | |
112 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 113 | cat >expected <<-EOF && |
86140d56 JL |
114 | Submodule sm1 $head2...$head4: |
115 | > Add foo5 | |
116 | > Add foo4 | |
117 | < Add foo3 | |
118 | < Add foo2 | |
119 | EOF | |
f8d186bb | 120 | test_cmp expected actual |
86140d56 JL |
121 | " |
122 | ||
123 | commit_file sm1 && | |
124 | mv sm1 sm1-bak && | |
125 | echo sm1 >sm1 && | |
126 | head5=$(git hash-object sm1 | cut -c1-7) && | |
127 | git add sm1 && | |
128 | rm -f sm1 && | |
129 | mv sm1-bak sm1 | |
130 | ||
131 | test_expect_success 'typechanged submodule(submodule->blob), --cached' " | |
132 | git diff --submodule=log --cached >actual && | |
f8d186bb | 133 | cat >expected <<-EOF && |
86140d56 JL |
134 | Submodule sm1 41fbea9...0000000 (submodule deleted) |
135 | diff --git a/sm1 b/sm1 | |
136 | new file mode 100644 | |
137 | index 0000000..9da5fb8 | |
138 | --- /dev/null | |
139 | +++ b/sm1 | |
140 | @@ -0,0 +1 @@ | |
141 | +sm1 | |
142 | EOF | |
f8d186bb | 143 | test_cmp expected actual |
86140d56 JL |
144 | " |
145 | ||
146 | test_expect_success 'typechanged submodule(submodule->blob)' " | |
147 | git diff --submodule=log >actual && | |
f8d186bb | 148 | cat >expected <<-EOF && |
86140d56 JL |
149 | diff --git a/sm1 b/sm1 |
150 | deleted file mode 100644 | |
151 | index 9da5fb8..0000000 | |
152 | --- a/sm1 | |
153 | +++ /dev/null | |
154 | @@ -1 +0,0 @@ | |
155 | -sm1 | |
156 | Submodule sm1 0000000...$head4 (new submodule) | |
157 | EOF | |
f8d186bb | 158 | test_cmp expected actual |
86140d56 JL |
159 | " |
160 | ||
161 | rm -rf sm1 && | |
162 | git checkout-index sm1 | |
163 | test_expect_success 'typechanged submodule(submodule->blob)' " | |
164 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 165 | cat >expected <<-EOF && |
86140d56 JL |
166 | Submodule sm1 $head4...0000000 (submodule deleted) |
167 | diff --git a/sm1 b/sm1 | |
168 | new file mode 100644 | |
169 | index 0000000..$head5 | |
170 | --- /dev/null | |
171 | +++ b/sm1 | |
172 | @@ -0,0 +1 @@ | |
173 | +sm1 | |
174 | EOF | |
f8d186bb | 175 | test_cmp expected actual |
86140d56 JL |
176 | " |
177 | ||
178 | rm -f sm1 && | |
179 | test_create_repo sm1 && | |
180 | head6=$(add_file sm1 foo6 foo7) | |
181 | fullhead6=$(cd sm1; git rev-list --max-count=1 $head6) | |
182 | test_expect_success 'nonexistent commit' " | |
183 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 184 | cat >expected <<-EOF && |
86140d56 JL |
185 | Submodule sm1 $head4...$head6 (commits not present) |
186 | EOF | |
f8d186bb | 187 | test_cmp expected actual |
86140d56 JL |
188 | " |
189 | ||
190 | commit_file | |
191 | test_expect_success 'typechanged submodule(blob->submodule)' " | |
192 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 193 | cat >expected <<-EOF && |
86140d56 JL |
194 | diff --git a/sm1 b/sm1 |
195 | deleted file mode 100644 | |
196 | index $head5..0000000 | |
197 | --- a/sm1 | |
198 | +++ /dev/null | |
199 | @@ -1 +0,0 @@ | |
200 | -sm1 | |
201 | Submodule sm1 0000000...$head6 (new submodule) | |
202 | EOF | |
f8d186bb | 203 | test_cmp expected actual |
86140d56 JL |
204 | " |
205 | ||
206 | commit_file sm1 && | |
721ceec1 JL |
207 | test_expect_success 'submodule is up to date' " |
208 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 209 | cat >expected <<-EOF && |
721ceec1 | 210 | EOF |
f8d186bb | 211 | test_cmp expected actual |
721ceec1 JL |
212 | " |
213 | ||
214 | test_expect_success 'submodule contains untracked content' " | |
215 | echo new > sm1/new-file && | |
216 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 217 | cat >expected <<-EOF && |
c7e1a736 | 218 | Submodule sm1 contains untracked content |
721ceec1 | 219 | EOF |
f8d186bb | 220 | test_cmp expected actual |
721ceec1 JL |
221 | " |
222 | ||
dd44d419 JL |
223 | test_expect_success 'submodule contains untracked content (untracked ignored)' " |
224 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
6ed7ddaa | 225 | ! test -s actual |
dd44d419 JL |
226 | " |
227 | ||
228 | test_expect_success 'submodule contains untracked content (dirty ignored)' " | |
229 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
6ed7ddaa | 230 | ! test -s actual |
dd44d419 JL |
231 | " |
232 | ||
233 | test_expect_success 'submodule contains untracked content (all ignored)' " | |
234 | git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual && | |
6ed7ddaa | 235 | ! test -s actual |
dd44d419 JL |
236 | " |
237 | ||
721ceec1 JL |
238 | test_expect_success 'submodule contains untracked and modifed content' " |
239 | echo new > sm1/foo6 && | |
240 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 241 | cat >expected <<-EOF && |
c7e1a736 JL |
242 | Submodule sm1 contains untracked content |
243 | Submodule sm1 contains modified content | |
721ceec1 | 244 | EOF |
f8d186bb | 245 | test_cmp expected actual |
721ceec1 JL |
246 | " |
247 | ||
dd44d419 JL |
248 | test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' " |
249 | echo new > sm1/foo6 && | |
250 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
f8d186bb | 251 | cat >expected <<-EOF && |
dd44d419 JL |
252 | Submodule sm1 contains modified content |
253 | EOF | |
f8d186bb | 254 | test_cmp expected actual |
dd44d419 JL |
255 | " |
256 | ||
257 | test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' " | |
258 | echo new > sm1/foo6 && | |
259 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
6ed7ddaa | 260 | ! test -s actual |
dd44d419 JL |
261 | " |
262 | ||
263 | test_expect_success 'submodule contains untracked and modifed content (all ignored)' " | |
264 | echo new > sm1/foo6 && | |
265 | git diff-index -p --ignore-submodules --submodule=log HEAD >actual && | |
6ed7ddaa | 266 | ! test -s actual |
dd44d419 JL |
267 | " |
268 | ||
721ceec1 JL |
269 | test_expect_success 'submodule contains modifed content' " |
270 | rm -f sm1/new-file && | |
271 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 272 | cat >expected <<-EOF && |
c7e1a736 | 273 | Submodule sm1 contains modified content |
721ceec1 | 274 | EOF |
f8d186bb | 275 | test_cmp expected actual |
721ceec1 JL |
276 | " |
277 | ||
278 | (cd sm1; git commit -mchange foo6 >/dev/null) && | |
279 | head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) && | |
280 | test_expect_success 'submodule is modified' " | |
281 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 282 | cat >expected <<-EOF && |
721ceec1 JL |
283 | Submodule sm1 $head6..$head8: |
284 | > change | |
285 | EOF | |
f8d186bb | 286 | test_cmp expected actual |
721ceec1 JL |
287 | " |
288 | ||
289 | test_expect_success 'modified submodule contains untracked content' " | |
290 | echo new > sm1/new-file && | |
291 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 292 | cat >expected <<-EOF && |
c7e1a736 JL |
293 | Submodule sm1 contains untracked content |
294 | Submodule sm1 $head6..$head8: | |
721ceec1 JL |
295 | > change |
296 | EOF | |
f8d186bb | 297 | test_cmp expected actual |
721ceec1 JL |
298 | " |
299 | ||
dd44d419 JL |
300 | test_expect_success 'modified submodule contains untracked content (untracked ignored)' " |
301 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
f8d186bb | 302 | cat >expected <<-EOF && |
dd44d419 JL |
303 | Submodule sm1 $head6..$head8: |
304 | > change | |
305 | EOF | |
f8d186bb | 306 | test_cmp expected actual |
dd44d419 JL |
307 | " |
308 | ||
309 | test_expect_success 'modified submodule contains untracked content (dirty ignored)' " | |
310 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
f8d186bb | 311 | cat >expected <<-EOF && |
dd44d419 JL |
312 | Submodule sm1 $head6..$head8: |
313 | > change | |
314 | EOF | |
f8d186bb | 315 | test_cmp expected actual |
dd44d419 JL |
316 | " |
317 | ||
318 | test_expect_success 'modified submodule contains untracked content (all ignored)' " | |
319 | git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual && | |
6ed7ddaa | 320 | ! test -s actual |
dd44d419 JL |
321 | " |
322 | ||
721ceec1 JL |
323 | test_expect_success 'modified submodule contains untracked and modifed content' " |
324 | echo modification >> sm1/foo6 && | |
325 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 326 | cat >expected <<-EOF && |
c7e1a736 JL |
327 | Submodule sm1 contains untracked content |
328 | Submodule sm1 contains modified content | |
329 | Submodule sm1 $head6..$head8: | |
721ceec1 JL |
330 | > change |
331 | EOF | |
f8d186bb | 332 | test_cmp expected actual |
721ceec1 JL |
333 | " |
334 | ||
dd44d419 JL |
335 | test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' " |
336 | echo modification >> sm1/foo6 && | |
337 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
f8d186bb | 338 | cat >expected <<-EOF && |
dd44d419 JL |
339 | Submodule sm1 contains modified content |
340 | Submodule sm1 $head6..$head8: | |
341 | > change | |
342 | EOF | |
f8d186bb | 343 | test_cmp expected actual |
dd44d419 JL |
344 | " |
345 | ||
346 | test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' " | |
347 | echo modification >> sm1/foo6 && | |
348 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
f8d186bb | 349 | cat >expected <<-EOF && |
dd44d419 JL |
350 | Submodule sm1 $head6..$head8: |
351 | > change | |
352 | EOF | |
f8d186bb | 353 | test_cmp expected actual |
dd44d419 JL |
354 | " |
355 | ||
356 | test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' " | |
357 | echo modification >> sm1/foo6 && | |
358 | git diff-index -p --ignore-submodules --submodule=log HEAD >actual && | |
6ed7ddaa | 359 | ! test -s actual |
dd44d419 JL |
360 | " |
361 | ||
721ceec1 JL |
362 | test_expect_success 'modified submodule contains modifed content' " |
363 | rm -f sm1/new-file && | |
364 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 365 | cat >expected <<-EOF && |
c7e1a736 JL |
366 | Submodule sm1 contains modified content |
367 | Submodule sm1 $head6..$head8: | |
721ceec1 JL |
368 | > change |
369 | EOF | |
f8d186bb | 370 | test_cmp expected actual |
721ceec1 JL |
371 | " |
372 | ||
86140d56 JL |
373 | rm -rf sm1 |
374 | test_expect_success 'deleted submodule' " | |
375 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 376 | cat >expected <<-EOF && |
86140d56 JL |
377 | Submodule sm1 $head6...0000000 (submodule deleted) |
378 | EOF | |
f8d186bb | 379 | test_cmp expected actual |
86140d56 JL |
380 | " |
381 | ||
382 | test_create_repo sm2 && | |
383 | head7=$(add_file sm2 foo8 foo9) && | |
384 | git add sm2 | |
385 | ||
386 | test_expect_success 'multiple submodules' " | |
387 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 388 | cat >expected <<-EOF && |
86140d56 JL |
389 | Submodule sm1 $head6...0000000 (submodule deleted) |
390 | Submodule sm2 0000000...$head7 (new submodule) | |
391 | EOF | |
f8d186bb | 392 | test_cmp expected actual |
86140d56 JL |
393 | " |
394 | ||
395 | test_expect_success 'path filter' " | |
396 | git diff-index -p --submodule=log HEAD sm2 >actual && | |
f8d186bb | 397 | cat >expected <<-EOF && |
86140d56 JL |
398 | Submodule sm2 0000000...$head7 (new submodule) |
399 | EOF | |
f8d186bb | 400 | test_cmp expected actual |
86140d56 JL |
401 | " |
402 | ||
403 | commit_file sm2 | |
404 | test_expect_success 'given commit' " | |
405 | git diff-index -p --submodule=log HEAD^ >actual && | |
f8d186bb | 406 | cat >expected <<-EOF && |
86140d56 JL |
407 | Submodule sm1 $head6...0000000 (submodule deleted) |
408 | Submodule sm2 0000000...$head7 (new submodule) | |
409 | EOF | |
f8d186bb | 410 | test_cmp expected actual |
86140d56 JL |
411 | " |
412 | ||
413 | test_expect_success 'given commit --submodule' " | |
414 | git diff-index -p --submodule HEAD^ >actual && | |
f8d186bb | 415 | cat >expected <<-EOF && |
86140d56 JL |
416 | Submodule sm1 $head6...0000000 (submodule deleted) |
417 | Submodule sm2 0000000...$head7 (new submodule) | |
418 | EOF | |
f8d186bb | 419 | test_cmp expected actual |
86140d56 JL |
420 | " |
421 | ||
422 | fullhead7=$(cd sm2; git rev-list --max-count=1 $head7) | |
423 | ||
424 | test_expect_success 'given commit --submodule=short' " | |
425 | git diff-index -p --submodule=short HEAD^ >actual && | |
f8d186bb | 426 | cat >expected <<-EOF && |
86140d56 JL |
427 | diff --git a/sm1 b/sm1 |
428 | deleted file mode 160000 | |
429 | index $head6..0000000 | |
430 | --- a/sm1 | |
431 | +++ /dev/null | |
432 | @@ -1 +0,0 @@ | |
433 | -Subproject commit $fullhead6 | |
434 | diff --git a/sm2 b/sm2 | |
435 | new file mode 160000 | |
436 | index 0000000..$head7 | |
437 | --- /dev/null | |
438 | +++ b/sm2 | |
439 | @@ -0,0 +1 @@ | |
440 | +Subproject commit $fullhead7 | |
441 | EOF | |
f8d186bb | 442 | test_cmp expected actual |
86140d56 JL |
443 | " |
444 | ||
eee49b6c JL |
445 | test_expect_success 'setup .git file for sm2' ' |
446 | (cd sm2 && | |
447 | REAL="$(pwd)/../.real" && | |
448 | mv .git "$REAL" | |
449 | echo "gitdir: $REAL" >.git) | |
450 | ' | |
451 | ||
452 | test_expect_success 'diff --submodule with .git file' ' | |
453 | git diff --submodule HEAD^ >actual && | |
f8d186bb | 454 | cat >expected <<-EOF && |
eee49b6c JL |
455 | Submodule sm1 $head6...0000000 (submodule deleted) |
456 | Submodule sm2 0000000...$head7 (new submodule) | |
457 | EOF | |
f8d186bb | 458 | test_cmp expected actual |
eee49b6c JL |
459 | ' |
460 | ||
86140d56 | 461 | test_done |