3 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
6 test_description
='Support for verbose submodule differences in git diff
8 This test tries to verify the sanity of the --submodule option of git diff.
19 echo "$name" >"$name" &&
22 git commit
-m "Add $name" ||
exit
24 git rev-parse
--short --verify HEAD
29 git commit
"$@" -m "Commit $*" >/dev
/null
32 test_create_repo sm1
&&
33 add_file . foo
>/dev
/null
35 head1
=$
(add_file sm1 foo1 foo2
)
36 fullhead1
=$
(cd sm1
; git rev-parse
--verify HEAD
)
38 test_expect_success
'added submodule' '
40 git diff-index -p --submodule=log HEAD >actual &&
41 cat >expected <<-EOF &&
42 Submodule sm1 0000000...$head1 (new submodule)
44 test_cmp expected actual
47 test_expect_success
'added submodule, set diff.submodule' '
48 git config diff.submodule log &&
50 git diff --cached >actual &&
51 cat >expected <<-EOF &&
52 Submodule sm1 0000000...$head1 (new submodule)
54 git config --unset diff.submodule &&
55 test_cmp expected actual
58 test_expect_success
'--submodule=short overrides diff.submodule' '
59 test_config diff.submodule log &&
61 git diff --submodule=short --cached >actual &&
62 cat >expected <<-EOF &&
63 diff --git a/sm1 b/sm1
69 +Subproject commit $fullhead1
71 test_cmp expected actual
74 test_expect_success
'diff.submodule does not affect plumbing' '
75 test_config diff.submodule log &&
76 git diff-index -p HEAD >actual &&
77 cat >expected <<-EOF &&
78 diff --git a/sm1 b/sm1
84 +Subproject commit $fullhead1
86 test_cmp expected actual
90 head2
=$
(add_file sm1 foo3
)
92 test_expect_success
'modified submodule(forward)' '
93 git diff-index -p --submodule=log HEAD >actual &&
94 cat >expected <<-EOF &&
95 Submodule sm1 $head1..$head2:
98 test_cmp expected actual
101 test_expect_success
'modified submodule(forward)' '
102 git diff --submodule=log >actual &&
103 cat >expected <<-EOF &&
104 Submodule sm1 $head1..$head2:
107 test_cmp expected actual
110 test_expect_success
'modified submodule(forward) --submodule' '
111 git diff --submodule >actual &&
112 cat >expected <<-EOF &&
113 Submodule sm1 $head1..$head2:
116 test_cmp expected actual
119 fullhead2
=$
(cd sm1
; git rev-parse
--verify HEAD
)
120 test_expect_success
'modified submodule(forward) --submodule=short' '
121 git diff --submodule=short >actual &&
122 cat >expected <<-EOF &&
123 diff --git a/sm1 b/sm1
124 index $head1..$head2 160000
128 -Subproject commit $fullhead1
129 +Subproject commit $fullhead2
131 test_cmp expected actual
137 git
reset --hard HEAD~
2 >/dev
/null
&&
138 git rev-parse
--short --verify HEAD
141 test_expect_success
'modified submodule(backward)' '
142 git diff-index -p --submodule=log HEAD >actual &&
143 cat >expected <<-EOF &&
144 Submodule sm1 $head2..$head3 (rewind):
148 test_cmp expected actual
151 head4
=$
(add_file sm1 foo4 foo5
)
152 test_expect_success
'modified submodule(backward and forward)' '
153 git diff-index -p --submodule=log HEAD >actual &&
154 cat >expected <<-EOF &&
155 Submodule sm1 $head2...$head4:
161 test_cmp expected actual
167 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
172 test_expect_success
'typechanged submodule(submodule->blob), --cached' '
173 git diff --submodule=log --cached >actual &&
174 cat >expected <<-EOF &&
175 Submodule sm1 $head4...0000000 (submodule deleted)
176 diff --git a/sm1 b/sm1
178 index 0000000..$head5
184 test_cmp expected actual
187 test_expect_success
'typechanged submodule(submodule->blob)' '
188 git diff --submodule=log >actual &&
189 cat >expected <<-EOF &&
190 diff --git a/sm1 b/sm1
191 deleted file mode 100644
192 index $head5..0000000
197 Submodule sm1 0000000...$head4 (new submodule)
199 test_cmp expected actual
203 git checkout-index sm1
204 test_expect_success
'typechanged submodule(submodule->blob)' '
205 git diff-index -p --submodule=log HEAD >actual &&
206 cat >expected <<-EOF &&
207 Submodule sm1 $head4...0000000 (submodule deleted)
208 diff --git a/sm1 b/sm1
210 index 0000000..$head5
216 test_cmp expected actual
220 test_create_repo sm1
&&
221 head6
=$
(add_file sm1 foo6 foo7
)
222 fullhead6
=$
(cd sm1
; git rev-parse
--verify HEAD
)
223 test_expect_success
'nonexistent commit' '
224 git diff-index -p --submodule=log HEAD >actual &&
225 cat >expected <<-EOF &&
226 Submodule sm1 $head4...$head6 (commits not present)
228 test_cmp expected actual
232 test_expect_success
'typechanged submodule(blob->submodule)' '
233 git diff-index -p --submodule=log HEAD >actual &&
234 cat >expected <<-EOF &&
235 diff --git a/sm1 b/sm1
236 deleted file mode 100644
237 index $head5..0000000
242 Submodule sm1 0000000...$head6 (new submodule)
244 test_cmp expected actual
248 test_expect_success
'submodule is up to date' '
249 git diff-index -p --submodule=log HEAD >actual &&
250 cat >expected <<-EOF &&
252 test_cmp expected actual
255 test_expect_success
'submodule contains untracked content' '
256 echo new > sm1/new-file &&
257 git diff-index -p --submodule=log HEAD >actual &&
258 cat >expected <<-EOF &&
259 Submodule sm1 contains untracked content
261 test_cmp expected actual
264 test_expect_success
'submodule contains untracked content (untracked ignored)' '
265 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
269 test_expect_success
'submodule contains untracked content (dirty ignored)' '
270 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
274 test_expect_success
'submodule contains untracked content (all ignored)' '
275 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
279 test_expect_success
'submodule contains untracked and modifed content' '
280 echo new > sm1/foo6 &&
281 git diff-index -p --submodule=log HEAD >actual &&
282 cat >expected <<-EOF &&
283 Submodule sm1 contains untracked content
284 Submodule sm1 contains modified content
286 test_cmp expected actual
289 test_expect_success
'submodule contains untracked and modifed content (untracked ignored)' '
290 echo new > sm1/foo6 &&
291 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
292 cat >expected <<-EOF &&
293 Submodule sm1 contains modified content
295 test_cmp expected actual
298 test_expect_success
'submodule contains untracked and modifed content (dirty ignored)' '
299 echo new > sm1/foo6 &&
300 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
304 test_expect_success
'submodule contains untracked and modifed content (all ignored)' '
305 echo new > sm1/foo6 &&
306 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
310 test_expect_success
'submodule contains modifed content' '
311 rm -f sm1/new-file &&
312 git diff-index -p --submodule=log HEAD >actual &&
313 cat >expected <<-EOF &&
314 Submodule sm1 contains modified content
316 test_cmp expected actual
319 (cd sm1
; git commit
-mchange foo6
>/dev
/null
) &&
320 head8
=$
(cd sm1
; git rev-parse
--short --verify HEAD
) &&
321 test_expect_success
'submodule is modified' '
322 git diff-index -p --submodule=log HEAD >actual &&
323 cat >expected <<-EOF &&
324 Submodule sm1 $head6..$head8:
327 test_cmp expected actual
330 test_expect_success
'modified submodule contains untracked content' '
331 echo new > sm1/new-file &&
332 git diff-index -p --submodule=log HEAD >actual &&
333 cat >expected <<-EOF &&
334 Submodule sm1 contains untracked content
335 Submodule sm1 $head6..$head8:
338 test_cmp expected actual
341 test_expect_success
'modified submodule contains untracked content (untracked ignored)' '
342 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
343 cat >expected <<-EOF &&
344 Submodule sm1 $head6..$head8:
347 test_cmp expected actual
350 test_expect_success
'modified submodule contains untracked content (dirty ignored)' '
351 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
352 cat >expected <<-EOF &&
353 Submodule sm1 $head6..$head8:
356 test_cmp expected actual
359 test_expect_success
'modified submodule contains untracked content (all ignored)' '
360 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
364 test_expect_success
'modified submodule contains untracked and modifed content' '
365 echo modification >> sm1/foo6 &&
366 git diff-index -p --submodule=log HEAD >actual &&
367 cat >expected <<-EOF &&
368 Submodule sm1 contains untracked content
369 Submodule sm1 contains modified content
370 Submodule sm1 $head6..$head8:
373 test_cmp expected actual
376 test_expect_success
'modified submodule contains untracked and modifed content (untracked ignored)' '
377 echo modification >> sm1/foo6 &&
378 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
379 cat >expected <<-EOF &&
380 Submodule sm1 contains modified content
381 Submodule sm1 $head6..$head8:
384 test_cmp expected actual
387 test_expect_success
'modified submodule contains untracked and modifed content (dirty ignored)' '
388 echo modification >> sm1/foo6 &&
389 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
390 cat >expected <<-EOF &&
391 Submodule sm1 $head6..$head8:
394 test_cmp expected actual
397 test_expect_success
'modified submodule contains untracked and modifed content (all ignored)' '
398 echo modification >> sm1/foo6 &&
399 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
403 test_expect_success
'modified submodule contains modifed content' '
404 rm -f sm1/new-file &&
405 git diff-index -p --submodule=log HEAD >actual &&
406 cat >expected <<-EOF &&
407 Submodule sm1 contains modified content
408 Submodule sm1 $head6..$head8:
411 test_cmp expected actual
415 test_expect_success
'deleted submodule' '
416 git diff-index -p --submodule=log HEAD >actual &&
417 cat >expected <<-EOF &&
418 Submodule sm1 $head6...0000000 (submodule deleted)
420 test_cmp expected actual
423 test_create_repo sm2
&&
424 head7
=$
(add_file sm2 foo8 foo9
) &&
427 test_expect_success
'multiple submodules' '
428 git diff-index -p --submodule=log HEAD >actual &&
429 cat >expected <<-EOF &&
430 Submodule sm1 $head6...0000000 (submodule deleted)
431 Submodule sm2 0000000...$head7 (new submodule)
433 test_cmp expected actual
436 test_expect_success
'path filter' '
437 git diff-index -p --submodule=log HEAD sm2 >actual &&
438 cat >expected <<-EOF &&
439 Submodule sm2 0000000...$head7 (new submodule)
441 test_cmp expected actual
445 test_expect_success
'given commit' '
446 git diff-index -p --submodule=log HEAD^ >actual &&
447 cat >expected <<-EOF &&
448 Submodule sm1 $head6...0000000 (submodule deleted)
449 Submodule sm2 0000000...$head7 (new submodule)
451 test_cmp expected actual
454 test_expect_success
'given commit --submodule' '
455 git diff-index -p --submodule HEAD^ >actual &&
456 cat >expected <<-EOF &&
457 Submodule sm1 $head6...0000000 (submodule deleted)
458 Submodule sm2 0000000...$head7 (new submodule)
460 test_cmp expected actual
463 fullhead7
=$
(cd sm2
; git rev-parse
--verify HEAD
)
465 test_expect_success
'given commit --submodule=short' '
466 git diff-index -p --submodule=short HEAD^ >actual &&
467 cat >expected <<-EOF &&
468 diff --git a/sm1 b/sm1
469 deleted file mode 160000
470 index $head6..0000000
474 -Subproject commit $fullhead6
475 diff --git a/sm2 b/sm2
477 index 0000000..$head7
481 +Subproject commit $fullhead7
483 test_cmp expected actual
486 test_expect_success
'setup .git file for sm2' '
488 REAL="$(pwd)/../.real" &&
490 echo "gitdir: $REAL" >.git)
493 test_expect_success
'diff --submodule with .git file' '
494 git diff --submodule HEAD^ >actual &&
495 cat >expected <<-EOF &&
496 Submodule sm1 $head6...0000000 (submodule deleted)
497 Submodule sm2 0000000...$head7 (new submodule)
499 test_cmp expected actual
502 test_expect_success
'diff --submodule with objects referenced by alternates' '
512 git clone -s ../sub_alt sub &&
515 git commit -m "sub a"
518 sha1_before=$(git rev-parse --short HEAD)
522 sha1_after=$(git rev-parse --short HEAD)
523 echo "Submodule sub $sha1_before..$sha1_after:
529 git checkout origin/master
531 git diff --submodule > ../actual
533 test_cmp expected actual