ident: don't consider '.' a crud
[git/gitster.git] / t / t4060-diff-submodule-option-diff-format.sh
blob97c6424cd51714eeadffd5899c709a409b1cedd9
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 test_expect_success 'nonexistent commit' '
365 git diff-index -p --submodule=diff HEAD >actual &&
366 cat >expected <<-EOF &&
367 Submodule sm1 $head4...$head6 (commits not present)
369 diff_cmp expected actual
372 commit_file
373 test_expect_success 'typechanged submodule(blob->submodule)' '
374 git diff-index -p --submodule=diff HEAD >actual &&
375 cat >expected <<-EOF &&
376 diff --git a/sm1 b/sm1
377 deleted file mode 100644
378 index 9da5fb8..0000000
379 --- a/sm1
380 +++ /dev/null
381 @@ -1 +0,0 @@
382 -sm1
383 Submodule sm1 0000000...$head6 (new submodule)
384 diff --git a/sm1/foo6 b/sm1/foo6
385 new file mode 100644
386 index 0000000..462398b
387 --- /dev/null
388 +++ b/sm1/foo6
389 @@ -0,0 +1 @@
390 +foo6
391 diff --git a/sm1/foo7 b/sm1/foo7
392 new file mode 100644
393 index 0000000..6e9262c
394 --- /dev/null
395 +++ b/sm1/foo7
396 @@ -0,0 +1 @@
397 +foo7
399 diff_cmp expected actual
402 commit_file sm1 &&
403 test_expect_success 'submodule is up to date' '
404 head7=$(git -C sm1 rev-parse --short --verify HEAD) &&
405 git diff-index -p --submodule=diff HEAD >actual &&
406 test_must_be_empty actual
409 test_expect_success 'submodule contains untracked content' '
410 echo new > sm1/new-file &&
411 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
412 cat >expected <<-EOF &&
413 Submodule sm1 contains untracked content
415 diff_cmp expected actual
418 test_expect_success 'submodule contains untracked content (untracked ignored)' '
419 git diff-index -p --submodule=diff HEAD >actual &&
420 test_must_be_empty actual
423 test_expect_success 'submodule contains untracked content (dirty ignored)' '
424 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
425 test_must_be_empty actual
428 test_expect_success 'submodule contains untracked content (all ignored)' '
429 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
430 test_must_be_empty actual
433 test_expect_success 'submodule contains untracked and modified content' '
434 echo new > sm1/foo6 &&
435 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
436 cat >expected <<-EOF &&
437 Submodule sm1 contains untracked content
438 Submodule sm1 contains modified content
439 diff --git a/sm1/foo6 b/sm1/foo6
440 index 462398b..3e75765 100644
441 --- a/sm1/foo6
442 +++ b/sm1/foo6
443 @@ -1 +1 @@
444 -foo6
445 +new
447 diff_cmp expected actual
450 # NOT OK
451 test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
452 echo new > sm1/foo6 &&
453 git diff-index -p --submodule=diff HEAD >actual &&
454 cat >expected <<-EOF &&
455 Submodule sm1 contains modified content
456 diff --git a/sm1/foo6 b/sm1/foo6
457 index 462398b..3e75765 100644
458 --- a/sm1/foo6
459 +++ b/sm1/foo6
460 @@ -1 +1 @@
461 -foo6
462 +new
464 diff_cmp expected actual
467 test_expect_success 'submodule contains untracked and modified content (dirty ignored)' '
468 echo new > sm1/foo6 &&
469 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
470 test_must_be_empty actual
473 test_expect_success 'submodule contains untracked and modified content (all ignored)' '
474 echo new > sm1/foo6 &&
475 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
476 test_must_be_empty actual
479 test_expect_success 'submodule contains modified content' '
480 rm -f sm1/new-file &&
481 git diff-index -p --submodule=diff HEAD >actual &&
482 cat >expected <<-EOF &&
483 Submodule sm1 contains modified content
484 diff --git a/sm1/foo6 b/sm1/foo6
485 index 462398b..3e75765 100644
486 --- a/sm1/foo6
487 +++ b/sm1/foo6
488 @@ -1 +1 @@
489 -foo6
490 +new
492 diff_cmp expected actual
495 (cd sm1; git commit -mchange foo6 >/dev/null) &&
496 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
497 test_expect_success 'submodule is modified' '
498 git diff-index -p --submodule=diff HEAD >actual &&
499 cat >expected <<-EOF &&
500 Submodule sm1 $head7..$head8:
501 diff --git a/sm1/foo6 b/sm1/foo6
502 index 462398b..3e75765 100644
503 --- a/sm1/foo6
504 +++ b/sm1/foo6
505 @@ -1 +1 @@
506 -foo6
507 +new
509 diff_cmp expected actual
512 test_expect_success 'modified submodule contains untracked content' '
513 echo new > sm1/new-file &&
514 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
515 cat >expected <<-EOF &&
516 Submodule sm1 contains untracked content
517 Submodule sm1 $head7..$head8:
518 diff --git a/sm1/foo6 b/sm1/foo6
519 index 462398b..3e75765 100644
520 --- a/sm1/foo6
521 +++ b/sm1/foo6
522 @@ -1 +1 @@
523 -foo6
524 +new
526 diff_cmp expected actual
529 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
530 git diff-index -p --submodule=diff HEAD >actual &&
531 cat >expected <<-EOF &&
532 Submodule sm1 $head7..$head8:
533 diff --git a/sm1/foo6 b/sm1/foo6
534 index 462398b..3e75765 100644
535 --- a/sm1/foo6
536 +++ b/sm1/foo6
537 @@ -1 +1 @@
538 -foo6
539 +new
541 diff_cmp expected actual
544 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
545 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
546 cat >expected <<-EOF &&
547 Submodule sm1 $head7..$head8:
548 diff --git a/sm1/foo6 b/sm1/foo6
549 index 462398b..3e75765 100644
550 --- a/sm1/foo6
551 +++ b/sm1/foo6
552 @@ -1 +1 @@
553 -foo6
554 +new
556 diff_cmp expected actual
559 test_expect_success 'modified submodule contains untracked content (all ignored)' '
560 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
561 test_must_be_empty actual
564 test_expect_success 'modified submodule contains untracked and modified content' '
565 echo modification >> sm1/foo6 &&
566 git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
567 cat >expected <<-EOF &&
568 Submodule sm1 contains untracked content
569 Submodule sm1 contains modified content
570 Submodule sm1 $head7..$head8:
571 diff --git a/sm1/foo6 b/sm1/foo6
572 index 462398b..dfda541 100644
573 --- a/sm1/foo6
574 +++ b/sm1/foo6
575 @@ -1 +1,2 @@
576 -foo6
577 +new
578 +modification
580 diff_cmp expected actual
583 test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
584 echo modification >> sm1/foo6 &&
585 git diff-index -p --submodule=diff HEAD >actual &&
586 cat >expected <<-EOF &&
587 Submodule sm1 contains modified content
588 Submodule sm1 $head7..$head8:
589 diff --git a/sm1/foo6 b/sm1/foo6
590 index 462398b..e20e2d9 100644
591 --- a/sm1/foo6
592 +++ b/sm1/foo6
593 @@ -1 +1,3 @@
594 -foo6
595 +new
596 +modification
597 +modification
599 diff_cmp expected actual
602 test_expect_success 'modified submodule contains untracked and modified content (dirty ignored)' '
603 echo modification >> sm1/foo6 &&
604 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
605 cat >expected <<-EOF &&
606 Submodule sm1 $head7..$head8:
607 diff --git a/sm1/foo6 b/sm1/foo6
608 index 462398b..3e75765 100644
609 --- a/sm1/foo6
610 +++ b/sm1/foo6
611 @@ -1 +1 @@
612 -foo6
613 +new
615 diff_cmp expected actual
618 test_expect_success 'modified submodule contains untracked and modified content (all ignored)' '
619 echo modification >> sm1/foo6 &&
620 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
621 test_must_be_empty actual
624 # NOT OK
625 test_expect_success 'modified submodule contains modified content' '
626 rm -f sm1/new-file &&
627 git diff-index -p --submodule=diff HEAD >actual &&
628 cat >expected <<-EOF &&
629 Submodule sm1 contains modified content
630 Submodule sm1 $head7..$head8:
631 diff --git a/sm1/foo6 b/sm1/foo6
632 index 462398b..ac466ca 100644
633 --- a/sm1/foo6
634 +++ b/sm1/foo6
635 @@ -1 +1,5 @@
636 -foo6
637 +new
638 +modification
639 +modification
640 +modification
641 +modification
643 diff_cmp expected actual
646 rm -rf sm1
647 test_expect_success 'deleted submodule' '
648 git diff-index -p --submodule=diff HEAD >actual &&
649 cat >expected <<-EOF &&
650 Submodule sm1 $head7...0000000 (submodule deleted)
652 diff_cmp expected actual
655 test_expect_success 'create second submodule' '
656 test_create_repo sm2 &&
657 head9=$(add_file sm2 foo8 foo9) &&
658 git add sm2
661 test_expect_success 'multiple submodules' '
662 git diff-index -p --submodule=diff HEAD >actual &&
663 cat >expected <<-EOF &&
664 Submodule sm1 $head7...0000000 (submodule deleted)
665 Submodule sm2 0000000...$head9 (new submodule)
666 diff --git a/sm2/foo8 b/sm2/foo8
667 new file mode 100644
668 index 0000000..db9916b
669 --- /dev/null
670 +++ b/sm2/foo8
671 @@ -0,0 +1 @@
672 +foo8
673 diff --git a/sm2/foo9 b/sm2/foo9
674 new file mode 100644
675 index 0000000..9c3b4f6
676 --- /dev/null
677 +++ b/sm2/foo9
678 @@ -0,0 +1 @@
679 +foo9
681 diff_cmp expected actual
684 test_expect_success 'path filter' '
685 git diff-index -p --submodule=diff HEAD sm2 >actual &&
686 cat >expected <<-EOF &&
687 Submodule sm2 0000000...$head9 (new submodule)
688 diff --git a/sm2/foo8 b/sm2/foo8
689 new file mode 100644
690 index 0000000..db9916b
691 --- /dev/null
692 +++ b/sm2/foo8
693 @@ -0,0 +1 @@
694 +foo8
695 diff --git a/sm2/foo9 b/sm2/foo9
696 new file mode 100644
697 index 0000000..9c3b4f6
698 --- /dev/null
699 +++ b/sm2/foo9
700 @@ -0,0 +1 @@
701 +foo9
703 diff_cmp expected actual
706 cat >.gitmodules <<-EOF
707 [submodule "sm2"]
708 path = sm2
709 url = bogus_url
711 git add .gitmodules
712 commit_file sm2 .gitmodules
714 test_expect_success 'given commit' '
715 git diff-index -p --submodule=diff HEAD^ >actual &&
716 cat >expected <<-EOF &&
717 diff --git a/.gitmodules b/.gitmodules
718 new file mode 100644
719 index 1234567..89abcde
720 --- /dev/null
721 +++ b/.gitmodules
722 @@ -0,0 +1,3 @@
723 +[submodule "sm2"]
724 +path = sm2
725 +url = bogus_url
726 Submodule sm1 $head7...0000000 (submodule deleted)
727 Submodule sm2 0000000...$head9 (new submodule)
728 diff --git a/sm2/foo8 b/sm2/foo8
729 new file mode 100644
730 index 0000000..db9916b
731 --- /dev/null
732 +++ b/sm2/foo8
733 @@ -0,0 +1 @@
734 +foo8
735 diff --git a/sm2/foo9 b/sm2/foo9
736 new file mode 100644
737 index 0000000..9c3b4f6
738 --- /dev/null
739 +++ b/sm2/foo9
740 @@ -0,0 +1 @@
741 +foo9
743 diff_cmp expected actual
746 test_expect_success 'setup .git file for sm2' '
747 git submodule absorbgitdirs sm2
750 test_expect_success 'diff --submodule=diff with .git file' '
751 git diff --submodule=diff HEAD^ >actual &&
752 cat >expected <<-EOF &&
753 diff --git a/.gitmodules b/.gitmodules
754 new file mode 100644
755 index 1234567..89abcde
756 --- /dev/null
757 +++ b/.gitmodules
758 @@ -0,0 +1,3 @@
759 +[submodule "sm2"]
760 +path = sm2
761 +url = bogus_url
762 Submodule sm1 $head7...0000000 (submodule deleted)
763 Submodule sm2 0000000...$head9 (new submodule)
764 diff --git a/sm2/foo8 b/sm2/foo8
765 new file mode 100644
766 index 0000000..db9916b
767 --- /dev/null
768 +++ b/sm2/foo8
769 @@ -0,0 +1 @@
770 +foo8
771 diff --git a/sm2/foo9 b/sm2/foo9
772 new file mode 100644
773 index 0000000..9c3b4f6
774 --- /dev/null
775 +++ b/sm2/foo9
776 @@ -0,0 +1 @@
777 +foo9
779 diff_cmp expected actual
782 mv sm2 sm2-bak
784 test_expect_success 'deleted submodule with .git file' '
785 git diff-index -p --submodule=diff HEAD >actual &&
786 cat >expected <<-EOF &&
787 Submodule sm1 $head7...0000000 (submodule deleted)
788 Submodule sm2 $head9...0000000 (submodule deleted)
789 diff --git a/sm2/foo8 b/sm2/foo8
790 deleted file mode 100644
791 index 1234567..89abcde
792 --- a/sm2/foo8
793 +++ /dev/null
794 @@ -1 +0,0 @@
795 -foo8
796 diff --git a/sm2/foo9 b/sm2/foo9
797 deleted file mode 100644
798 index 1234567..89abcde
799 --- a/sm2/foo9
800 +++ /dev/null
801 @@ -1 +0,0 @@
802 -foo9
804 diff_cmp expected actual
807 echo submodule-to-blob>sm2
809 test_expect_success 'typechanged(submodule->blob) submodule with .git file' '
810 git diff-index -p --submodule=diff HEAD >actual &&
811 cat >expected <<-EOF &&
812 Submodule sm1 $head7...0000000 (submodule deleted)
813 Submodule sm2 $head9...0000000 (submodule deleted)
814 diff --git a/sm2/foo8 b/sm2/foo8
815 deleted file mode 100644
816 index 1234567..89abcde
817 --- a/sm2/foo8
818 +++ /dev/null
819 @@ -1 +0,0 @@
820 -foo8
821 diff --git a/sm2/foo9 b/sm2/foo9
822 deleted file mode 100644
823 index 1234567..89abcde
824 --- a/sm2/foo9
825 +++ /dev/null
826 @@ -1 +0,0 @@
827 -foo9
828 diff --git a/sm2 b/sm2
829 new file mode 100644
830 index 1234567..89abcde
831 --- /dev/null
832 +++ b/sm2
833 @@ -0,0 +1 @@
834 +submodule-to-blob
836 diff_cmp expected actual
839 rm sm2
840 mv sm2-bak sm2
842 test_expect_success 'setup nested submodule' '
843 git -c protocol.file.allow=always -C sm2 submodule add ../sm2 nested &&
844 git -C sm2 commit -a -m "nested sub" &&
845 head10=$(git -C sm2 rev-parse --short --verify HEAD)
848 test_expect_success 'move nested submodule HEAD' '
849 echo "nested content" >sm2/nested/file &&
850 git -C sm2/nested add file &&
851 git -C sm2/nested commit --allow-empty -m "new HEAD" &&
852 head11=$(git -C sm2/nested rev-parse --short --verify HEAD)
855 test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
856 cat >expected <<-EOF &&
857 Submodule nested $head9..$head11:
858 diff --git a/nested/file b/nested/file
859 new file mode 100644
860 index 0000000..ca281f5
861 --- /dev/null
862 +++ b/nested/file
863 @@ -0,0 +1 @@
864 +nested content
866 git -C sm2 diff --submodule=diff >actual 2>err &&
867 test_must_be_empty err &&
868 diff_cmp expected actual
871 test_expect_success 'diff --submodule=diff recurses into nested submodules' '
872 cat >expected <<-EOF &&
873 Submodule sm1 $head7...0000000 (submodule deleted)
874 Submodule sm2 contains modified content
875 Submodule sm2 $head9..$head10:
876 diff --git a/sm2/.gitmodules b/sm2/.gitmodules
877 new file mode 100644
878 index 0000000..3a816b8
879 --- /dev/null
880 +++ b/sm2/.gitmodules
881 @@ -0,0 +1,3 @@
882 +[submodule "nested"]
883 + path = nested
884 + url = ../sm2
885 Submodule nested 0000000...$head11 (new submodule)
886 diff --git a/sm2/nested/file b/sm2/nested/file
887 new file mode 100644
888 index 0000000..ca281f5
889 --- /dev/null
890 +++ b/sm2/nested/file
891 @@ -0,0 +1 @@
892 +nested content
893 diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
894 new file mode 100644
895 index 0000000..db9916b
896 --- /dev/null
897 +++ b/sm2/nested/foo8
898 @@ -0,0 +1 @@
899 +foo8
900 diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
901 new file mode 100644
902 index 0000000..9c3b4f6
903 --- /dev/null
904 +++ b/sm2/nested/foo9
905 @@ -0,0 +1 @@
906 +foo9
908 git diff --submodule=diff >actual 2>err &&
909 test_must_be_empty err &&
910 diff_cmp expected actual
913 (cd sm2; commit_file nested)
914 commit_file sm2
915 head12=$(cd sm2; git rev-parse --short --verify HEAD)
917 mv sm2 sm2-bak
919 test_expect_success 'diff --submodule=diff recurses into deleted nested submodules' '
920 cat >expected <<-EOF &&
921 Submodule sm1 $head7...0000000 (submodule deleted)
922 Submodule sm2 $head12...0000000 (submodule deleted)
923 diff --git a/sm2/.gitmodules b/sm2/.gitmodules
924 deleted file mode 100644
925 index 3a816b8..0000000
926 --- a/sm2/.gitmodules
927 +++ /dev/null
928 @@ -1,3 +0,0 @@
929 -[submodule "nested"]
930 - path = nested
931 - url = ../sm2
932 diff --git a/sm2/foo8 b/sm2/foo8
933 deleted file mode 100644
934 index db9916b..0000000
935 --- a/sm2/foo8
936 +++ /dev/null
937 @@ -1 +0,0 @@
938 -foo8
939 diff --git a/sm2/foo9 b/sm2/foo9
940 deleted file mode 100644
941 index 9c3b4f6..0000000
942 --- a/sm2/foo9
943 +++ /dev/null
944 @@ -1 +0,0 @@
945 -foo9
946 Submodule nested $head11...0000000 (submodule deleted)
947 diff --git a/sm2/nested/file b/sm2/nested/file
948 deleted file mode 100644
949 index ca281f5..0000000
950 --- a/sm2/nested/file
951 +++ /dev/null
952 @@ -1 +0,0 @@
953 -nested content
954 diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
955 deleted file mode 100644
956 index db9916b..0000000
957 --- a/sm2/nested/foo8
958 +++ /dev/null
959 @@ -1 +0,0 @@
960 -foo8
961 diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
962 deleted file mode 100644
963 index 9c3b4f6..0000000
964 --- a/sm2/nested/foo9
965 +++ /dev/null
966 @@ -1 +0,0 @@
967 -foo9
969 git diff --submodule=diff >actual 2>err &&
970 test_must_be_empty err &&
971 diff_cmp expected actual
974 mv sm2-bak sm2
976 test_done