make_transient_cache_entry(): optionally alloc from mem_pool
[git/debian.git] / t / t4060-diff-submodule-option-diff-format.sh
blobdc7b242697d7760e5cff1fd5e166ba895ce605c6
1 #!/bin/sh
3 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
4 # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
5 # Copyright (c) 2016 Jacob Keller (copy + convert to --submodule=diff)
8 test_description='Support for diff format verbose submodule difference in git diff
10 This test tries to verify the sanity of --submodule=diff option of git diff.
13 . ./test-lib.sh
15 # Tested non-UTF-8 encoding
16 test_encoding="ISO8859-1"
18 # String "added" in German (translated with Google Translate), encoded in UTF-8,
19 # used in sample commit log messages in add_file() function below.
20 added=$(printf "hinzugef\303\274gt")
22 add_file () {
24 cd "$1" &&
25 shift &&
26 for name
28 echo "$name" >"$name" &&
29 git add "$name" &&
30 test_tick &&
31 # "git commit -m" would break MinGW, as Windows refuse to pass
32 # $test_encoding encoded parameter to git.
33 echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
34 git -c "i18n.commitEncoding=$test_encoding" commit -F -
35 done >/dev/null &&
36 git rev-parse --short --verify HEAD
40 commit_file () {
41 test_tick &&
42 git commit "$@" -m "Commit $*" >/dev/null
45 diff_cmp () {
46 for i in "$1" "$2"
48 sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
49 -e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
50 "$i" >"$i.compare" || return 1
51 done &&
52 test_cmp "$1.compare" "$2.compare" &&
53 rm -f "$1.compare" "$2.compare"
56 test_expect_success 'setup repository' '
57 test_create_repo sm1 &&
58 add_file . foo &&
59 head1=$(add_file sm1 foo1 foo2) &&
60 fullhead1=$(git -C sm1 rev-parse --verify HEAD)
63 test_expect_success 'added submodule' '
64 git add sm1 &&
65 git diff-index -p --submodule=diff HEAD >actual &&
66 cat >expected <<-EOF &&
67 Submodule sm1 0000000...$head1 (new submodule)
68 diff --git a/sm1/foo1 b/sm1/foo1
69 new file mode 100644
70 index 0000000..1715acd
71 --- /dev/null
72 +++ b/sm1/foo1
73 @@ -0,0 +1 @@
74 +foo1
75 diff --git a/sm1/foo2 b/sm1/foo2
76 new file mode 100644
77 index 0000000..54b060e
78 --- /dev/null
79 +++ b/sm1/foo2
80 @@ -0,0 +1 @@
81 +foo2
82 EOF
83 diff_cmp expected actual
86 test_expect_success 'added submodule, set diff.submodule' '
87 test_config diff.submodule log &&
88 git add sm1 &&
89 git diff-index -p --submodule=diff HEAD >actual &&
90 cat >expected <<-EOF &&
91 Submodule sm1 0000000...$head1 (new submodule)
92 diff --git a/sm1/foo1 b/sm1/foo1
93 new file mode 100644
94 index 0000000..1715acd
95 --- /dev/null
96 +++ b/sm1/foo1
97 @@ -0,0 +1 @@
98 +foo1
99 diff --git a/sm1/foo2 b/sm1/foo2
100 new file mode 100644
101 index 0000000..54b060e
102 --- /dev/null
103 +++ b/sm1/foo2
104 @@ -0,0 +1 @@
105 +foo2
107 diff_cmp expected actual
110 test_expect_success '--submodule=short overrides diff.submodule' '
111 test_config diff.submodule log &&
112 git add sm1 &&
113 git diff --submodule=short --cached >actual &&
114 cat >expected <<-EOF &&
115 diff --git a/sm1 b/sm1
116 new file mode 160000
117 index 0000000..$head1
118 --- /dev/null
119 +++ b/sm1
120 @@ -0,0 +1 @@
121 +Subproject commit $fullhead1
123 diff_cmp expected actual
126 test_expect_success 'diff.submodule does not affect plumbing' '
127 test_config diff.submodule log &&
128 git diff-index -p HEAD >actual &&
129 cat >expected <<-EOF &&
130 diff --git a/sm1 b/sm1
131 new file mode 160000
132 index 0000000..$head1
133 --- /dev/null
134 +++ b/sm1
135 @@ -0,0 +1 @@
136 +Subproject commit $fullhead1
138 diff_cmp expected actual
141 commit_file sm1 &&
142 head2=$(add_file sm1 foo3)
144 test_expect_success 'modified submodule(forward)' '
145 git diff-index -p --submodule=diff HEAD >actual &&
146 cat >expected <<-EOF &&
147 Submodule sm1 $head1..$head2:
148 diff --git a/sm1/foo3 b/sm1/foo3
149 new file mode 100644
150 index 0000000..c1ec6c6
151 --- /dev/null
152 +++ b/sm1/foo3
153 @@ -0,0 +1 @@
154 +foo3
156 diff_cmp expected actual
159 test_expect_success 'modified submodule(forward)' '
160 git diff --submodule=diff >actual &&
161 cat >expected <<-EOF &&
162 Submodule sm1 $head1..$head2:
163 diff --git a/sm1/foo3 b/sm1/foo3
164 new file mode 100644
165 index 0000000..c1ec6c6
166 --- /dev/null
167 +++ b/sm1/foo3
168 @@ -0,0 +1 @@
169 +foo3
171 diff_cmp expected actual
174 test_expect_success 'modified submodule(forward) --submodule' '
175 git diff --submodule >actual &&
176 cat >expected <<-EOF &&
177 Submodule sm1 $head1..$head2:
178 > Add foo3 ($added foo3)
180 diff_cmp expected actual
183 fullhead2=$(cd sm1; git rev-parse --verify HEAD)
184 test_expect_success 'modified submodule(forward) --submodule=short' '
185 git diff --submodule=short >actual &&
186 cat >expected <<-EOF &&
187 diff --git a/sm1 b/sm1
188 index $head1..$head2 160000
189 --- a/sm1
190 +++ b/sm1
191 @@ -1 +1 @@
192 -Subproject commit $fullhead1
193 +Subproject commit $fullhead2
195 diff_cmp expected actual
198 commit_file sm1 &&
199 head3=$(
200 cd sm1 &&
201 git reset --hard HEAD~2 >/dev/null &&
202 git rev-parse --short --verify HEAD
205 test_expect_success 'modified submodule(backward)' '
206 git diff-index -p --submodule=diff HEAD >actual &&
207 cat >expected <<-EOF &&
208 Submodule sm1 $head2..$head3 (rewind):
209 diff --git a/sm1/foo2 b/sm1/foo2
210 deleted file mode 100644
211 index 54b060e..0000000
212 --- a/sm1/foo2
213 +++ /dev/null
214 @@ -1 +0,0 @@
215 -foo2
216 diff --git a/sm1/foo3 b/sm1/foo3
217 deleted file mode 100644
218 index c1ec6c6..0000000
219 --- a/sm1/foo3
220 +++ /dev/null
221 @@ -1 +0,0 @@
222 -foo3
224 diff_cmp expected actual
227 head4=$(add_file sm1 foo4 foo5)
228 test_expect_success 'modified submodule(backward and forward)' '
229 git diff-index -p --submodule=diff HEAD >actual &&
230 cat >expected <<-EOF &&
231 Submodule sm1 $head2...$head4:
232 diff --git a/sm1/foo2 b/sm1/foo2
233 deleted file mode 100644
234 index 54b060e..0000000
235 --- a/sm1/foo2
236 +++ /dev/null
237 @@ -1 +0,0 @@
238 -foo2
239 diff --git a/sm1/foo3 b/sm1/foo3
240 deleted file mode 100644
241 index c1ec6c6..0000000
242 --- a/sm1/foo3
243 +++ /dev/null
244 @@ -1 +0,0 @@
245 -foo3
246 diff --git a/sm1/foo4 b/sm1/foo4
247 new file mode 100644
248 index 0000000..a0016db
249 --- /dev/null
250 +++ b/sm1/foo4
251 @@ -0,0 +1 @@
252 +foo4
253 diff --git a/sm1/foo5 b/sm1/foo5
254 new file mode 100644
255 index 0000000..d6f2413
256 --- /dev/null
257 +++ b/sm1/foo5
258 @@ -0,0 +1 @@
259 +foo5
261 diff_cmp expected actual
264 commit_file sm1 &&
265 mv sm1 sm1-bak &&
266 echo sm1 >sm1 &&
267 head5=$(git hash-object sm1 | cut -c1-7) &&
268 git add sm1 &&
269 rm -f sm1 &&
270 mv sm1-bak sm1
272 test_expect_success 'typechanged submodule(submodule->blob), --cached' '
273 git diff --submodule=diff --cached >actual &&
274 cat >expected <<-EOF &&
275 Submodule sm1 $head4...0000000 (submodule deleted)
276 diff --git a/sm1/foo1 b/sm1/foo1
277 deleted file mode 100644
278 index 1715acd..0000000
279 --- a/sm1/foo1
280 +++ /dev/null
281 @@ -1 +0,0 @@
282 -foo1
283 diff --git a/sm1/foo4 b/sm1/foo4
284 deleted file mode 100644
285 index a0016db..0000000
286 --- a/sm1/foo4
287 +++ /dev/null
288 @@ -1 +0,0 @@
289 -foo4
290 diff --git a/sm1/foo5 b/sm1/foo5
291 deleted file mode 100644
292 index d6f2413..0000000
293 --- a/sm1/foo5
294 +++ /dev/null
295 @@ -1 +0,0 @@
296 -foo5
297 diff --git a/sm1 b/sm1
298 new file mode 100644
299 index 0000000..9da5fb8
300 --- /dev/null
301 +++ b/sm1
302 @@ -0,0 +1 @@
303 +sm1
305 diff_cmp expected actual
308 test_expect_success 'typechanged submodule(submodule->blob)' '
309 git diff --submodule=diff >actual &&
310 cat >expected <<-EOF &&
311 diff --git a/sm1 b/sm1
312 deleted file mode 100644
313 index 9da5fb8..0000000
314 --- a/sm1
315 +++ /dev/null
316 @@ -1 +0,0 @@
317 -sm1
318 Submodule sm1 0000000...$head4 (new submodule)
319 diff --git a/sm1/foo1 b/sm1/foo1
320 new file mode 100644
321 index 0000000..1715acd
322 --- /dev/null
323 +++ b/sm1/foo1
324 @@ -0,0 +1 @@
325 +foo1
326 diff --git a/sm1/foo4 b/sm1/foo4
327 new file mode 100644
328 index 0000000..a0016db
329 --- /dev/null
330 +++ b/sm1/foo4
331 @@ -0,0 +1 @@
332 +foo4
333 diff --git a/sm1/foo5 b/sm1/foo5
334 new file mode 100644
335 index 0000000..d6f2413
336 --- /dev/null
337 +++ b/sm1/foo5
338 @@ -0,0 +1 @@
339 +foo5
341 diff_cmp expected actual
344 rm -rf sm1 &&
345 git checkout-index sm1
346 test_expect_success 'typechanged submodule(submodule->blob)' '
347 git diff-index -p --submodule=diff HEAD >actual &&
348 cat >expected <<-EOF &&
349 Submodule sm1 $head4...0000000 (submodule deleted)
350 diff --git a/sm1 b/sm1
351 new file mode 100644
352 index 0000000..9da5fb8
353 --- /dev/null
354 +++ b/sm1
355 @@ -0,0 +1 @@
356 +sm1
358 diff_cmp expected actual
361 rm -f sm1 &&
362 test_create_repo sm1 &&
363 head6=$(add_file sm1 foo6 foo7)
364 fullhead6=$(cd sm1; git rev-parse --verify HEAD)
365 test_expect_success 'nonexistent commit' '
366 git diff-index -p --submodule=diff HEAD >actual &&
367 cat >expected <<-EOF &&
368 Submodule sm1 $head4...$head6 (commits not present)
370 diff_cmp expected actual
373 commit_file
374 test_expect_success 'typechanged submodule(blob->submodule)' '
375 git diff-index -p --submodule=diff HEAD >actual &&
376 cat >expected <<-EOF &&
377 diff --git a/sm1 b/sm1
378 deleted file mode 100644
379 index 9da5fb8..0000000
380 --- a/sm1
381 +++ /dev/null
382 @@ -1 +0,0 @@
383 -sm1
384 Submodule sm1 0000000...$head6 (new submodule)
385 diff --git a/sm1/foo6 b/sm1/foo6
386 new file mode 100644
387 index 0000000..462398b
388 --- /dev/null
389 +++ b/sm1/foo6
390 @@ -0,0 +1 @@
391 +foo6
392 diff --git a/sm1/foo7 b/sm1/foo7
393 new file mode 100644
394 index 0000000..6e9262c
395 --- /dev/null
396 +++ b/sm1/foo7
397 @@ -0,0 +1 @@
398 +foo7
400 diff_cmp expected actual
403 commit_file sm1 &&
404 test_expect_success 'submodule is up to date' '
405 head7=$(git -C sm1 rev-parse --short --verify HEAD) &&
406 git diff-index -p --submodule=diff HEAD >actual &&
407 test_must_be_empty actual
410 test_expect_success 'submodule contains untracked content' '
411 echo new > sm1/new-file &&
412 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
413 cat >expected <<-EOF &&
414 Submodule sm1 contains untracked content
416 diff_cmp expected actual
419 test_expect_success 'submodule contains untracked content (untracked ignored)' '
420 git diff-index -p --submodule=diff HEAD >actual &&
421 test_must_be_empty actual
424 test_expect_success 'submodule contains untracked content (dirty ignored)' '
425 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
426 test_must_be_empty actual
429 test_expect_success 'submodule contains untracked content (all ignored)' '
430 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
431 test_must_be_empty actual
434 test_expect_success 'submodule contains untracked and modified content' '
435 echo new > sm1/foo6 &&
436 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
437 cat >expected <<-EOF &&
438 Submodule sm1 contains untracked content
439 Submodule sm1 contains modified content
440 diff --git a/sm1/foo6 b/sm1/foo6
441 index 462398b..3e75765 100644
442 --- a/sm1/foo6
443 +++ b/sm1/foo6
444 @@ -1 +1 @@
445 -foo6
446 +new
448 diff_cmp expected actual
451 # NOT OK
452 test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
453 echo new > sm1/foo6 &&
454 git diff-index -p --submodule=diff HEAD >actual &&
455 cat >expected <<-EOF &&
456 Submodule sm1 contains modified content
457 diff --git a/sm1/foo6 b/sm1/foo6
458 index 462398b..3e75765 100644
459 --- a/sm1/foo6
460 +++ b/sm1/foo6
461 @@ -1 +1 @@
462 -foo6
463 +new
465 diff_cmp expected actual
468 test_expect_success 'submodule contains untracked and modified content (dirty ignored)' '
469 echo new > sm1/foo6 &&
470 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
471 test_must_be_empty actual
474 test_expect_success 'submodule contains untracked and modified content (all ignored)' '
475 echo new > sm1/foo6 &&
476 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
477 test_must_be_empty actual
480 test_expect_success 'submodule contains modified content' '
481 rm -f sm1/new-file &&
482 git diff-index -p --submodule=diff HEAD >actual &&
483 cat >expected <<-EOF &&
484 Submodule sm1 contains modified content
485 diff --git a/sm1/foo6 b/sm1/foo6
486 index 462398b..3e75765 100644
487 --- a/sm1/foo6
488 +++ b/sm1/foo6
489 @@ -1 +1 @@
490 -foo6
491 +new
493 diff_cmp expected actual
496 (cd sm1; git commit -mchange foo6 >/dev/null) &&
497 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
498 test_expect_success 'submodule is modified' '
499 git diff-index -p --submodule=diff HEAD >actual &&
500 cat >expected <<-EOF &&
501 Submodule sm1 $head7..$head8:
502 diff --git a/sm1/foo6 b/sm1/foo6
503 index 462398b..3e75765 100644
504 --- a/sm1/foo6
505 +++ b/sm1/foo6
506 @@ -1 +1 @@
507 -foo6
508 +new
510 diff_cmp expected actual
513 test_expect_success 'modified submodule contains untracked content' '
514 echo new > sm1/new-file &&
515 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
516 cat >expected <<-EOF &&
517 Submodule sm1 contains untracked content
518 Submodule sm1 $head7..$head8:
519 diff --git a/sm1/foo6 b/sm1/foo6
520 index 462398b..3e75765 100644
521 --- a/sm1/foo6
522 +++ b/sm1/foo6
523 @@ -1 +1 @@
524 -foo6
525 +new
527 diff_cmp expected actual
530 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
531 git diff-index -p --submodule=diff HEAD >actual &&
532 cat >expected <<-EOF &&
533 Submodule sm1 $head7..$head8:
534 diff --git a/sm1/foo6 b/sm1/foo6
535 index 462398b..3e75765 100644
536 --- a/sm1/foo6
537 +++ b/sm1/foo6
538 @@ -1 +1 @@
539 -foo6
540 +new
542 diff_cmp expected actual
545 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
546 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
547 cat >expected <<-EOF &&
548 Submodule sm1 $head7..$head8:
549 diff --git a/sm1/foo6 b/sm1/foo6
550 index 462398b..3e75765 100644
551 --- a/sm1/foo6
552 +++ b/sm1/foo6
553 @@ -1 +1 @@
554 -foo6
555 +new
557 diff_cmp expected actual
560 test_expect_success 'modified submodule contains untracked content (all ignored)' '
561 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
562 test_must_be_empty actual
565 test_expect_success 'modified submodule contains untracked and modified content' '
566 echo modification >> sm1/foo6 &&
567 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
568 cat >expected <<-EOF &&
569 Submodule sm1 contains untracked content
570 Submodule sm1 contains modified content
571 Submodule sm1 $head7..$head8:
572 diff --git a/sm1/foo6 b/sm1/foo6
573 index 462398b..dfda541 100644
574 --- a/sm1/foo6
575 +++ b/sm1/foo6
576 @@ -1 +1,2 @@
577 -foo6
578 +new
579 +modification
581 diff_cmp expected actual
584 test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
585 echo modification >> sm1/foo6 &&
586 git diff-index -p --submodule=diff HEAD >actual &&
587 cat >expected <<-EOF &&
588 Submodule sm1 contains modified content
589 Submodule sm1 $head7..$head8:
590 diff --git a/sm1/foo6 b/sm1/foo6
591 index 462398b..e20e2d9 100644
592 --- a/sm1/foo6
593 +++ b/sm1/foo6
594 @@ -1 +1,3 @@
595 -foo6
596 +new
597 +modification
598 +modification
600 diff_cmp expected actual
603 test_expect_success 'modified submodule contains untracked and modified content (dirty ignored)' '
604 echo modification >> sm1/foo6 &&
605 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
606 cat >expected <<-EOF &&
607 Submodule sm1 $head7..$head8:
608 diff --git a/sm1/foo6 b/sm1/foo6
609 index 462398b..3e75765 100644
610 --- a/sm1/foo6
611 +++ b/sm1/foo6
612 @@ -1 +1 @@
613 -foo6
614 +new
616 diff_cmp expected actual
619 test_expect_success 'modified submodule contains untracked and modified content (all ignored)' '
620 echo modification >> sm1/foo6 &&
621 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
622 test_must_be_empty actual
625 # NOT OK
626 test_expect_success 'modified submodule contains modified content' '
627 rm -f sm1/new-file &&
628 git diff-index -p --submodule=diff HEAD >actual &&
629 cat >expected <<-EOF &&
630 Submodule sm1 contains modified content
631 Submodule sm1 $head7..$head8:
632 diff --git a/sm1/foo6 b/sm1/foo6
633 index 462398b..ac466ca 100644
634 --- a/sm1/foo6
635 +++ b/sm1/foo6
636 @@ -1 +1,5 @@
637 -foo6
638 +new
639 +modification
640 +modification
641 +modification
642 +modification
644 diff_cmp expected actual
647 rm -rf sm1
648 test_expect_success 'deleted submodule' '
649 git diff-index -p --submodule=diff HEAD >actual &&
650 cat >expected <<-EOF &&
651 Submodule sm1 $head7...0000000 (submodule deleted)
653 diff_cmp expected actual
656 test_expect_success 'create second submodule' '
657 test_create_repo sm2 &&
658 head9=$(add_file sm2 foo8 foo9) &&
659 git add sm2
662 test_expect_success 'multiple submodules' '
663 git diff-index -p --submodule=diff HEAD >actual &&
664 cat >expected <<-EOF &&
665 Submodule sm1 $head7...0000000 (submodule deleted)
666 Submodule sm2 0000000...$head9 (new submodule)
667 diff --git a/sm2/foo8 b/sm2/foo8
668 new file mode 100644
669 index 0000000..db9916b
670 --- /dev/null
671 +++ b/sm2/foo8
672 @@ -0,0 +1 @@
673 +foo8
674 diff --git a/sm2/foo9 b/sm2/foo9
675 new file mode 100644
676 index 0000000..9c3b4f6
677 --- /dev/null
678 +++ b/sm2/foo9
679 @@ -0,0 +1 @@
680 +foo9
682 diff_cmp expected actual
685 test_expect_success 'path filter' '
686 git diff-index -p --submodule=diff HEAD sm2 >actual &&
687 cat >expected <<-EOF &&
688 Submodule sm2 0000000...$head9 (new submodule)
689 diff --git a/sm2/foo8 b/sm2/foo8
690 new file mode 100644
691 index 0000000..db9916b
692 --- /dev/null
693 +++ b/sm2/foo8
694 @@ -0,0 +1 @@
695 +foo8
696 diff --git a/sm2/foo9 b/sm2/foo9
697 new file mode 100644
698 index 0000000..9c3b4f6
699 --- /dev/null
700 +++ b/sm2/foo9
701 @@ -0,0 +1 @@
702 +foo9
704 diff_cmp expected actual
707 commit_file sm2
708 test_expect_success 'given commit' '
709 git diff-index -p --submodule=diff HEAD^ >actual &&
710 cat >expected <<-EOF &&
711 Submodule sm1 $head7...0000000 (submodule deleted)
712 Submodule sm2 0000000...$head9 (new submodule)
713 diff --git a/sm2/foo8 b/sm2/foo8
714 new file mode 100644
715 index 0000000..db9916b
716 --- /dev/null
717 +++ b/sm2/foo8
718 @@ -0,0 +1 @@
719 +foo8
720 diff --git a/sm2/foo9 b/sm2/foo9
721 new file mode 100644
722 index 0000000..9c3b4f6
723 --- /dev/null
724 +++ b/sm2/foo9
725 @@ -0,0 +1 @@
726 +foo9
728 diff_cmp expected actual
731 test_expect_success 'setup .git file for sm2' '
732 (cd sm2 &&
733 REAL="$(pwd)/../.real" &&
734 mv .git "$REAL" &&
735 echo "gitdir: $REAL" >.git)
738 test_expect_success 'diff --submodule=diff with .git file' '
739 git diff --submodule=diff HEAD^ >actual &&
740 cat >expected <<-EOF &&
741 Submodule sm1 $head7...0000000 (submodule deleted)
742 Submodule sm2 0000000...$head9 (new submodule)
743 diff --git a/sm2/foo8 b/sm2/foo8
744 new file mode 100644
745 index 0000000..db9916b
746 --- /dev/null
747 +++ b/sm2/foo8
748 @@ -0,0 +1 @@
749 +foo8
750 diff --git a/sm2/foo9 b/sm2/foo9
751 new file mode 100644
752 index 0000000..9c3b4f6
753 --- /dev/null
754 +++ b/sm2/foo9
755 @@ -0,0 +1 @@
756 +foo9
758 diff_cmp expected actual
761 test_expect_success 'setup nested submodule' '
762 git submodule add -f ./sm2 &&
763 git commit -a -m "add sm2" &&
764 git -C sm2 submodule add ../sm2 nested &&
765 git -C sm2 commit -a -m "nested sub" &&
766 head10=$(git -C sm2 rev-parse --short --verify HEAD)
769 test_expect_success 'move nested submodule HEAD' '
770 echo "nested content" >sm2/nested/file &&
771 git -C sm2/nested add file &&
772 git -C sm2/nested commit --allow-empty -m "new HEAD" &&
773 head11=$(git -C sm2/nested rev-parse --short --verify HEAD)
776 test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
777 cat >expected <<-EOF &&
778 Submodule nested $head9..$head11:
779 diff --git a/nested/file b/nested/file
780 new file mode 100644
781 index 0000000..ca281f5
782 --- /dev/null
783 +++ b/nested/file
784 @@ -0,0 +1 @@
785 +nested content
787 git -C sm2 diff --submodule=diff >actual 2>err &&
788 test_must_be_empty err &&
789 diff_cmp expected actual
792 test_expect_success 'diff --submodule=diff recurses into nested submodules' '
793 cat >expected <<-EOF &&
794 Submodule sm2 contains modified content
795 Submodule sm2 $head9..$head10:
796 diff --git a/sm2/.gitmodules b/sm2/.gitmodules
797 new file mode 100644
798 index 0000000..3a816b8
799 --- /dev/null
800 +++ b/sm2/.gitmodules
801 @@ -0,0 +1,3 @@
802 +[submodule "nested"]
803 + path = nested
804 + url = ../sm2
805 Submodule nested 0000000...$head11 (new submodule)
806 diff --git a/sm2/nested/file b/sm2/nested/file
807 new file mode 100644
808 index 0000000..ca281f5
809 --- /dev/null
810 +++ b/sm2/nested/file
811 @@ -0,0 +1 @@
812 +nested content
813 diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
814 new file mode 100644
815 index 0000000..db9916b
816 --- /dev/null
817 +++ b/sm2/nested/foo8
818 @@ -0,0 +1 @@
819 +foo8
820 diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
821 new file mode 100644
822 index 0000000..9c3b4f6
823 --- /dev/null
824 +++ b/sm2/nested/foo9
825 @@ -0,0 +1 @@
826 +foo9
828 git diff --submodule=diff >actual 2>err &&
829 test_must_be_empty err &&
830 diff_cmp expected actual
833 test_done