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
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
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 &&
59 head1=$(add_file sm1 foo1 foo2) &&
60 fullhead1=$(git -C sm1 rev-parse --verify HEAD)
63 test_expect_success
'added submodule' '
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
70 index 0000000..1715acd
75 diff --git a/sm1/foo2 b/sm1/foo2
77 index 0000000..54b060e
83 diff_cmp expected actual
86 test_expect_success
'added submodule, set diff.submodule' '
87 test_config diff.submodule log &&
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
94 index 0000000..1715acd
99 diff --git a/sm1/foo2 b/sm1/foo2
101 index 0000000..54b060e
107 diff_cmp expected actual
110 test_expect_success
'--submodule=short overrides diff.submodule' '
111 test_config diff.submodule log &&
113 git diff --submodule=short --cached >actual &&
114 cat >expected <<-EOF &&
115 diff --git a/sm1 b/sm1
117 index 0000000..$head1
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
132 index 0000000..$head1
136 +Subproject commit $fullhead1
138 diff_cmp expected actual
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
150 index 0000000..c1ec6c6
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
165 index 0000000..c1ec6c6
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
192 -Subproject commit $fullhead1
193 +Subproject commit $fullhead2
195 diff_cmp expected actual
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
216 diff --git a/sm1/foo3 b/sm1/foo3
217 deleted file mode 100644
218 index c1ec6c6..0000000
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
239 diff --git a/sm1/foo3 b/sm1/foo3
240 deleted file mode 100644
241 index c1ec6c6..0000000
246 diff --git a/sm1/foo4 b/sm1/foo4
248 index 0000000..a0016db
253 diff --git a/sm1/foo5 b/sm1/foo5
255 index 0000000..d6f2413
261 diff_cmp expected actual
267 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
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
283 diff --git a/sm1/foo4 b/sm1/foo4
284 deleted file mode 100644
285 index a0016db..0000000
290 diff --git a/sm1/foo5 b/sm1/foo5
291 deleted file mode 100644
292 index d6f2413..0000000
297 diff --git a/sm1 b/sm1
299 index 0000000..9da5fb8
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
318 Submodule sm1 0000000...$head4 (new submodule)
319 diff --git a/sm1/foo1 b/sm1/foo1
321 index 0000000..1715acd
326 diff --git a/sm1/foo4 b/sm1/foo4
328 index 0000000..a0016db
333 diff --git a/sm1/foo5 b/sm1/foo5
335 index 0000000..d6f2413
341 diff_cmp expected actual
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
352 index 0000000..9da5fb8
358 diff_cmp expected actual
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
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
383 Submodule sm1 0000000...$head6 (new submodule)
384 diff --git a/sm1/foo6 b/sm1/foo6
386 index 0000000..462398b
391 diff --git a/sm1/foo7 b/sm1/foo7
393 index 0000000..6e9262c
399 diff_cmp expected actual
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
447 diff_cmp expected actual
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
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
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
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
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
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
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
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
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
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
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
643 diff_cmp expected actual
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) &&
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
668 index 0000000..db9916b
673 diff --git a/sm2/foo9 b/sm2/foo9
675 index 0000000..9c3b4f6
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
690 index 0000000..db9916b
695 diff --git a/sm2/foo9 b/sm2/foo9
697 index 0000000..9c3b4f6
703 diff_cmp expected actual
706 cat >.gitmodules
<<-EOF
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
719 index 1234567..89abcde
726 Submodule sm1 $head7...0000000 (submodule deleted)
727 Submodule sm2 0000000...$head9 (new submodule)
728 diff --git a/sm2/foo8 b/sm2/foo8
730 index 0000000..db9916b
735 diff --git a/sm2/foo9 b/sm2/foo9
737 index 0000000..9c3b4f6
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
755 index 1234567..89abcde
762 Submodule sm1 $head7...0000000 (submodule deleted)
763 Submodule sm2 0000000...$head9 (new submodule)
764 diff --git a/sm2/foo8 b/sm2/foo8
766 index 0000000..db9916b
771 diff --git a/sm2/foo9 b/sm2/foo9
773 index 0000000..9c3b4f6
779 diff_cmp expected actual
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
796 diff --git a/sm2/foo9 b/sm2/foo9
797 deleted file mode 100644
798 index 1234567..89abcde
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
821 diff --git a/sm2/foo9 b/sm2/foo9
822 deleted file mode 100644
823 index 1234567..89abcde
828 diff --git a/sm2 b/sm2
830 index 1234567..89abcde
836 diff_cmp expected actual
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
860 index 0000000..ca281f5
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
878 index 0000000..3a816b8
880 +++ b/sm2/.gitmodules
882 +[submodule "nested"]
885 Submodule nested 0000000...$head11 (new submodule)
886 diff --git a/sm2/nested/file b/sm2/nested/file
888 index 0000000..ca281f5
890 +++ b/sm2/nested/file
893 diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
895 index 0000000..db9916b
897 +++ b/sm2/nested/foo8
900 diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
902 index 0000000..9c3b4f6
904 +++ b/sm2/nested/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
)
915 head12
=$
(cd sm2
; git rev-parse
--short --verify HEAD
)
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
929 -[submodule "nested"]
932 diff --git a/sm2/foo8 b/sm2/foo8
933 deleted file mode 100644
934 index db9916b..0000000
939 diff --git a/sm2/foo9 b/sm2/foo9
940 deleted file mode 100644
941 index 9c3b4f6..0000000
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
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
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
969 git diff --submodule=diff >actual 2>err &&
970 test_must_be_empty err &&
971 diff_cmp expected actual