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.
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")
28 echo "$name" >"$name" &&
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 -
36 git rev-parse
--short --verify HEAD
42 git commit
"$@" -m "Commit $*" >/dev
/null
45 test_expect_success
'setup repository' '
46 test_create_repo sm1 &&
48 head1=$(add_file sm1 foo1 foo2) &&
49 fullhead1=$(git -C sm1 rev-parse --verify HEAD)
52 test_expect_success
'added submodule' '
54 git diff-index -p --submodule=diff HEAD >actual &&
55 cat >expected <<-EOF &&
56 Submodule sm1 0000000...$head1 (new submodule)
57 diff --git a/sm1/foo1 b/sm1/foo1
59 index 0000000..1715acd
64 diff --git a/sm1/foo2 b/sm1/foo2
66 index 0000000..54b060e
72 test_cmp expected actual
75 test_expect_success
'added submodule, set diff.submodule' '
76 test_config diff.submodule log &&
78 git diff-index -p --submodule=diff HEAD >actual &&
79 cat >expected <<-EOF &&
80 Submodule sm1 0000000...$head1 (new submodule)
81 diff --git a/sm1/foo1 b/sm1/foo1
83 index 0000000..1715acd
88 diff --git a/sm1/foo2 b/sm1/foo2
90 index 0000000..54b060e
96 test_cmp expected actual
99 test_expect_success
'--submodule=short overrides diff.submodule' '
100 test_config diff.submodule log &&
102 git diff --submodule=short --cached >actual &&
103 cat >expected <<-EOF &&
104 diff --git a/sm1 b/sm1
106 index 0000000..$head1
110 +Subproject commit $fullhead1
112 test_cmp expected actual
115 test_expect_success
'diff.submodule does not affect plumbing' '
116 test_config diff.submodule log &&
117 git diff-index -p HEAD >actual &&
118 cat >expected <<-EOF &&
119 diff --git a/sm1 b/sm1
121 index 0000000..$head1
125 +Subproject commit $fullhead1
127 test_cmp expected actual
131 head2
=$
(add_file sm1 foo3
)
133 test_expect_success
'modified submodule(forward)' '
134 git diff-index -p --submodule=diff HEAD >actual &&
135 cat >expected <<-EOF &&
136 Submodule sm1 $head1..$head2:
137 diff --git a/sm1/foo3 b/sm1/foo3
139 index 0000000..c1ec6c6
145 test_cmp expected actual
148 test_expect_success
'modified submodule(forward)' '
149 git diff --submodule=diff >actual &&
150 cat >expected <<-EOF &&
151 Submodule sm1 $head1..$head2:
152 diff --git a/sm1/foo3 b/sm1/foo3
154 index 0000000..c1ec6c6
160 test_cmp expected actual
163 test_expect_success
'modified submodule(forward) --submodule' '
164 git diff --submodule >actual &&
165 cat >expected <<-EOF &&
166 Submodule sm1 $head1..$head2:
167 > Add foo3 ($added foo3)
169 test_cmp expected actual
172 fullhead2
=$
(cd sm1
; git rev-parse
--verify HEAD
)
173 test_expect_success
'modified submodule(forward) --submodule=short' '
174 git diff --submodule=short >actual &&
175 cat >expected <<-EOF &&
176 diff --git a/sm1 b/sm1
177 index $head1..$head2 160000
181 -Subproject commit $fullhead1
182 +Subproject commit $fullhead2
184 test_cmp expected actual
190 git
reset --hard HEAD~
2 >/dev
/null
&&
191 git rev-parse
--short --verify HEAD
194 test_expect_success
'modified submodule(backward)' '
195 git diff-index -p --submodule=diff HEAD >actual &&
196 cat >expected <<-EOF &&
197 Submodule sm1 $head2..$head3 (rewind):
198 diff --git a/sm1/foo2 b/sm1/foo2
199 deleted file mode 100644
200 index 54b060e..0000000
205 diff --git a/sm1/foo3 b/sm1/foo3
206 deleted file mode 100644
207 index c1ec6c6..0000000
213 test_cmp expected actual
216 head4
=$
(add_file sm1 foo4 foo5
)
217 test_expect_success
'modified submodule(backward and forward)' '
218 git diff-index -p --submodule=diff HEAD >actual &&
219 cat >expected <<-EOF &&
220 Submodule sm1 $head2...$head4:
221 diff --git a/sm1/foo2 b/sm1/foo2
222 deleted file mode 100644
223 index 54b060e..0000000
228 diff --git a/sm1/foo3 b/sm1/foo3
229 deleted file mode 100644
230 index c1ec6c6..0000000
235 diff --git a/sm1/foo4 b/sm1/foo4
237 index 0000000..a0016db
242 diff --git a/sm1/foo5 b/sm1/foo5
244 index 0000000..d6f2413
250 test_cmp expected actual
256 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
261 test_expect_success
'typechanged submodule(submodule->blob), --cached' '
262 git diff --submodule=diff --cached >actual &&
263 cat >expected <<-EOF &&
264 Submodule sm1 $head4...0000000 (submodule deleted)
265 diff --git a/sm1/foo1 b/sm1/foo1
266 deleted file mode 100644
267 index 1715acd..0000000
272 diff --git a/sm1/foo4 b/sm1/foo4
273 deleted file mode 100644
274 index a0016db..0000000
279 diff --git a/sm1/foo5 b/sm1/foo5
280 deleted file mode 100644
281 index d6f2413..0000000
286 diff --git a/sm1 b/sm1
288 index 0000000..9da5fb8
294 test_cmp expected actual
297 test_expect_success
'typechanged submodule(submodule->blob)' '
298 git diff --submodule=diff >actual &&
299 cat >expected <<-EOF &&
300 diff --git a/sm1 b/sm1
301 deleted file mode 100644
302 index 9da5fb8..0000000
307 Submodule sm1 0000000...$head4 (new submodule)
308 diff --git a/sm1/foo1 b/sm1/foo1
310 index 0000000..1715acd
315 diff --git a/sm1/foo4 b/sm1/foo4
317 index 0000000..a0016db
322 diff --git a/sm1/foo5 b/sm1/foo5
324 index 0000000..d6f2413
330 test_cmp expected actual
334 git checkout-index sm1
335 test_expect_success
'typechanged submodule(submodule->blob)' '
336 git diff-index -p --submodule=diff HEAD >actual &&
337 cat >expected <<-EOF &&
338 Submodule sm1 $head4...0000000 (submodule deleted)
339 diff --git a/sm1 b/sm1
341 index 0000000..9da5fb8
347 test_cmp expected actual
351 test_create_repo sm1
&&
352 head6
=$
(add_file sm1 foo6 foo7
)
353 fullhead6
=$
(cd sm1
; git rev-parse
--verify HEAD
)
354 test_expect_success
'nonexistent commit' '
355 git diff-index -p --submodule=diff HEAD >actual &&
356 cat >expected <<-EOF &&
357 Submodule sm1 $head4...$head6 (commits not present)
359 test_cmp expected actual
363 test_expect_success
'typechanged submodule(blob->submodule)' '
364 git diff-index -p --submodule=diff HEAD >actual &&
365 cat >expected <<-EOF &&
366 diff --git a/sm1 b/sm1
367 deleted file mode 100644
368 index 9da5fb8..0000000
373 Submodule sm1 0000000...$head6 (new submodule)
374 diff --git a/sm1/foo6 b/sm1/foo6
376 index 0000000..462398b
381 diff --git a/sm1/foo7 b/sm1/foo7
383 index 0000000..6e9262c
389 test_cmp expected actual
393 test_expect_success
'submodule is up to date' '
394 git diff-index -p --submodule=diff HEAD >actual &&
395 test_must_be_empty actual
398 test_expect_success
'submodule contains untracked content' '
399 echo new > sm1/new-file &&
400 git diff-index -p --submodule=diff HEAD >actual &&
401 cat >expected <<-EOF &&
402 Submodule sm1 contains untracked content
404 test_cmp expected actual
407 test_expect_success
'submodule contains untracked content (untracked ignored)' '
408 git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
409 test_must_be_empty actual
412 test_expect_success
'submodule contains untracked content (dirty ignored)' '
413 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
414 test_must_be_empty actual
417 test_expect_success
'submodule contains untracked content (all ignored)' '
418 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
419 test_must_be_empty actual
422 test_expect_success
'submodule contains untracked and modified content' '
423 echo new > sm1/foo6 &&
424 git diff-index -p --submodule=diff HEAD >actual &&
425 cat >expected <<-EOF &&
426 Submodule sm1 contains untracked content
427 Submodule sm1 contains modified content
428 diff --git a/sm1/foo6 b/sm1/foo6
429 index 462398b..3e75765 100644
436 test_cmp expected actual
440 test_expect_success
'submodule contains untracked and modified content (untracked ignored)' '
441 echo new > sm1/foo6 &&
442 git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
443 cat >expected <<-EOF &&
444 Submodule sm1 contains modified content
445 diff --git a/sm1/foo6 b/sm1/foo6
446 index 462398b..3e75765 100644
453 test_cmp expected actual
456 test_expect_success
'submodule contains untracked and modified content (dirty ignored)' '
457 echo new > sm1/foo6 &&
458 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
459 test_must_be_empty actual
462 test_expect_success
'submodule contains untracked and modified content (all ignored)' '
463 echo new > sm1/foo6 &&
464 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
465 test_must_be_empty actual
468 test_expect_success
'submodule contains modified content' '
469 rm -f sm1/new-file &&
470 git diff-index -p --submodule=diff HEAD >actual &&
471 cat >expected <<-EOF &&
472 Submodule sm1 contains modified content
473 diff --git a/sm1/foo6 b/sm1/foo6
474 index 462398b..3e75765 100644
481 test_cmp expected actual
484 (cd sm1
; git commit
-mchange foo6
>/dev
/null
) &&
485 head8
=$
(cd sm1
; git rev-parse
--short --verify HEAD
) &&
486 test_expect_success
'submodule is modified' '
487 git diff-index -p --submodule=diff HEAD >actual &&
488 cat >expected <<-EOF &&
489 Submodule sm1 17243c9..$head8:
490 diff --git a/sm1/foo6 b/sm1/foo6
491 index 462398b..3e75765 100644
498 test_cmp expected actual
501 test_expect_success
'modified submodule contains untracked content' '
502 echo new > sm1/new-file &&
503 git diff-index -p --submodule=diff HEAD >actual &&
504 cat >expected <<-EOF &&
505 Submodule sm1 contains untracked content
506 Submodule sm1 17243c9..$head8:
507 diff --git a/sm1/foo6 b/sm1/foo6
508 index 462398b..3e75765 100644
515 test_cmp expected actual
518 test_expect_success
'modified submodule contains untracked content (untracked ignored)' '
519 git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
520 cat >expected <<-EOF &&
521 Submodule sm1 17243c9..$head8:
522 diff --git a/sm1/foo6 b/sm1/foo6
523 index 462398b..3e75765 100644
530 test_cmp expected actual
533 test_expect_success
'modified submodule contains untracked content (dirty ignored)' '
534 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
535 cat >expected <<-EOF &&
536 Submodule sm1 17243c9..cfce562:
537 diff --git a/sm1/foo6 b/sm1/foo6
538 index 462398b..3e75765 100644
545 test_cmp expected actual
548 test_expect_success
'modified submodule contains untracked content (all ignored)' '
549 git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
550 test_must_be_empty actual
553 test_expect_success
'modified submodule contains untracked and modified content' '
554 echo modification >> sm1/foo6 &&
555 git diff-index -p --submodule=diff HEAD >actual &&
556 cat >expected <<-EOF &&
557 Submodule sm1 contains untracked content
558 Submodule sm1 contains modified content
559 Submodule sm1 17243c9..cfce562:
560 diff --git a/sm1/foo6 b/sm1/foo6
561 index 462398b..dfda541 100644
569 test_cmp expected actual
572 test_expect_success
'modified submodule contains untracked and modified content (untracked ignored)' '
573 echo modification >> sm1/foo6 &&
574 git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
575 cat >expected <<-EOF &&
576 Submodule sm1 contains modified content
577 Submodule sm1 17243c9..cfce562:
578 diff --git a/sm1/foo6 b/sm1/foo6
579 index 462398b..e20e2d9 100644
588 test_cmp expected actual
591 test_expect_success
'modified submodule contains untracked and modified content (dirty ignored)' '
592 echo modification >> sm1/foo6 &&
593 git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
594 cat >expected <<-EOF &&
595 Submodule sm1 17243c9..cfce562:
596 diff --git a/sm1/foo6 b/sm1/foo6
597 index 462398b..3e75765 100644
604 test_cmp expected actual
607 test_expect_success
'modified submodule contains untracked and modified content (all ignored)' '
608 echo modification >> sm1/foo6 &&
609 git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
610 test_must_be_empty actual
614 test_expect_success
'modified submodule contains modified content' '
615 rm -f sm1/new-file &&
616 git diff-index -p --submodule=diff HEAD >actual &&
617 cat >expected <<-EOF &&
618 Submodule sm1 contains modified content
619 Submodule sm1 17243c9..cfce562:
620 diff --git a/sm1/foo6 b/sm1/foo6
621 index 462398b..ac466ca 100644
632 test_cmp expected actual
636 test_expect_success
'deleted submodule' '
637 git diff-index -p --submodule=diff HEAD >actual &&
638 cat >expected <<-EOF &&
639 Submodule sm1 17243c9...0000000 (submodule deleted)
641 test_cmp expected actual
644 test_expect_success
'create second submodule' '
645 test_create_repo sm2 &&
646 head7=$(add_file sm2 foo8 foo9) &&
650 test_expect_success
'multiple submodules' '
651 git diff-index -p --submodule=diff HEAD >actual &&
652 cat >expected <<-EOF &&
653 Submodule sm1 17243c9...0000000 (submodule deleted)
654 Submodule sm2 0000000...a5a65c9 (new submodule)
655 diff --git a/sm2/foo8 b/sm2/foo8
657 index 0000000..db9916b
662 diff --git a/sm2/foo9 b/sm2/foo9
664 index 0000000..9c3b4f6
670 test_cmp expected actual
673 test_expect_success
'path filter' '
674 git diff-index -p --submodule=diff HEAD sm2 >actual &&
675 cat >expected <<-EOF &&
676 Submodule sm2 0000000...a5a65c9 (new submodule)
677 diff --git a/sm2/foo8 b/sm2/foo8
679 index 0000000..db9916b
684 diff --git a/sm2/foo9 b/sm2/foo9
686 index 0000000..9c3b4f6
692 test_cmp expected actual
696 test_expect_success
'given commit' '
697 git diff-index -p --submodule=diff HEAD^ >actual &&
698 cat >expected <<-EOF &&
699 Submodule sm1 17243c9...0000000 (submodule deleted)
700 Submodule sm2 0000000...a5a65c9 (new submodule)
701 diff --git a/sm2/foo8 b/sm2/foo8
703 index 0000000..db9916b
708 diff --git a/sm2/foo9 b/sm2/foo9
710 index 0000000..9c3b4f6
716 test_cmp expected actual
719 test_expect_success
'setup .git file for sm2' '
721 REAL="$(pwd)/../.real" &&
723 echo "gitdir: $REAL" >.git)
726 test_expect_success
'diff --submodule=diff with .git file' '
727 git diff --submodule=diff HEAD^ >actual &&
728 cat >expected <<-EOF &&
729 Submodule sm1 17243c9...0000000 (submodule deleted)
730 Submodule sm2 0000000...a5a65c9 (new submodule)
731 diff --git a/sm2/foo8 b/sm2/foo8
733 index 0000000..db9916b
738 diff --git a/sm2/foo9 b/sm2/foo9
740 index 0000000..9c3b4f6
746 test_cmp expected actual
749 test_expect_success
'setup nested submodule' '
750 git submodule add -f ./sm2 &&
751 git commit -a -m "add sm2" &&
752 git -C sm2 submodule add ../sm2 nested &&
753 git -C sm2 commit -a -m "nested sub"
756 test_expect_success
'move nested submodule HEAD' '
757 echo "nested content" >sm2/nested/file &&
758 git -C sm2/nested add file &&
759 git -C sm2/nested commit --allow-empty -m "new HEAD"
762 test_expect_success
'diff --submodule=diff with moved nested submodule HEAD' '
763 cat >expected <<-EOF &&
764 Submodule nested a5a65c9..b55928c:
765 diff --git a/nested/file b/nested/file
767 index 0000000..ca281f5
773 git -C sm2 diff --submodule=diff >actual 2>err &&
774 test_must_be_empty err &&
775 test_cmp expected actual
778 test_expect_success
'diff --submodule=diff recurses into nested submodules' '
779 cat >expected <<-EOF &&
780 Submodule sm2 contains modified content
781 Submodule sm2 a5a65c9..280969a:
782 diff --git a/sm2/.gitmodules b/sm2/.gitmodules
784 index 0000000..3a816b8
786 +++ b/sm2/.gitmodules
788 +[submodule "nested"]
791 Submodule nested 0000000...b55928c (new submodule)
792 diff --git a/sm2/nested/file b/sm2/nested/file
794 index 0000000..ca281f5
796 +++ b/sm2/nested/file
799 diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
801 index 0000000..db9916b
803 +++ b/sm2/nested/foo8
806 diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
808 index 0000000..9c3b4f6
810 +++ b/sm2/nested/foo9
814 git diff --submodule=diff >actual 2>err &&
815 test_must_be_empty err &&
816 test_cmp expected actual