3 # Copyright (c) 2007 Lars Hjemli
6 test_description='Basic porcelain support for submodules
8 This test tries to verify basic sanity of the init, update and status
9 subcommands of git submodule.
14 test_expect_success 'submodule deinit works on empty repository' '
15 git submodule deinit --all
18 test_expect_success 'setup - initial commit' '
21 git commit -m "initial commit" &&
25 test_expect_success 'submodule init aborts on missing .gitmodules file' '
26 test_when_finished "git update-index --remove sub" &&
27 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
28 # missing the .gitmodules file here
29 test_must_fail git submodule init 2>actual &&
30 test_i18ngrep "No url found for submodule path" actual
33 test_expect_success 'submodule update aborts on missing .gitmodules file' '
34 test_when_finished "git update-index --remove sub" &&
35 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
36 # missing the .gitmodules file here
37 git submodule update sub 2>actual &&
38 test_i18ngrep "Submodule path .sub. not initialized" actual
41 test_expect_success 'submodule update aborts on missing gitmodules url' '
42 test_when_finished "git update-index --remove sub" &&
43 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
44 test_when_finished "rm -f .gitmodules" &&
45 git config -f .gitmodules submodule.s.path sub &&
46 test_must_fail git submodule init
49 test_expect_success 'setup - repository in init subdirectory' '
56 git commit -m "submodule commit 1" &&
57 git tag -a -m "rev-1" rev-1
61 test_expect_success 'setup - commit with gitlink' '
65 git commit -m "super commit 1"
68 test_expect_success 'setup - hide init subdirectory' '
72 test_expect_success 'setup - repository to add submodules to' '
74 git init addtest-ignore
77 # The 'submodule add' tests need some repository to add as a submodule.
78 # The trash directory is a good one as any. We need to canonicalize
79 # the name, though, as some tests compare it to the absolute path git
80 # generates, which will expand symbolic links.
84 git for-each-ref --format='%(refname)' 'refs/heads/*'
93 listbranches >"$dotdot/heads" &&
94 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
95 git rev-parse HEAD >"$dotdot/head-sha1" &&
96 git update-index --refresh &&
97 git diff-files --exit-code &&
98 git clean -n -d -x >"$dotdot/untracked"
102 test_expect_success 'submodule add' '
103 echo "refs/heads/master" >expect &&
108 git submodule add -q "$submodurl" submod >actual &&
109 test_must_be_empty actual &&
110 echo "gitdir: ../.git/modules/submod" >expect &&
111 test_cmp expect submod/.git &&
114 git config core.worktree >actual &&
115 echo "../../../submod" >expect &&
116 test_cmp expect actual &&
122 rm -f heads head untracked &&
123 inspect addtest/submod ../.. &&
124 test_cmp expect heads &&
125 test_cmp expect head &&
126 test_cmp empty untracked
129 test_expect_success 'submodule add to .gitignored path fails' '
132 cat <<-\EOF >expect &&
133 The following path is ignored by one of your .gitignore files:
135 Use -f if you really want to add it.
137 # Does not use test_commit due to the ignore
138 echo "*" > .gitignore &&
139 git add --force .gitignore &&
140 git commit -m"Ignore everything" &&
141 ! git submodule add "$submodurl" submod >actual 2>&1 &&
142 test_i18ncmp expect actual
146 test_expect_success 'submodule add to .gitignored path with --force' '
149 git submodule add --force "$submodurl" submod
153 test_expect_success 'submodule add to reconfigure existing submodule with --force' '
156 git submodule add --force bogus-url submod &&
157 git submodule add -b initial "$submodurl" submod-branch &&
158 test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
159 test "bogus-url" = "$(git config submodule.submod.url)" &&
161 git submodule add --force "$submodurl" submod
162 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
163 test "$submodurl" = "$(git config submodule.submod.url)"
167 test_expect_success 'submodule add --branch' '
168 echo "refs/heads/initial" >expect-head &&
169 cat <<-\EOF >expect-heads &&
177 git submodule add -b initial "$submodurl" submod-branch &&
178 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
182 rm -f heads head untracked &&
183 inspect addtest/submod-branch ../.. &&
184 test_cmp expect-heads heads &&
185 test_cmp expect-head head &&
186 test_cmp empty untracked
189 test_expect_success 'submodule add with ./ in path' '
190 echo "refs/heads/master" >expect &&
195 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
199 rm -f heads head untracked &&
200 inspect addtest/dotsubmod/frotz ../../.. &&
201 test_cmp expect heads &&
202 test_cmp expect head &&
203 test_cmp empty untracked
206 test_expect_success 'submodule add with /././ in path' '
207 echo "refs/heads/master" >expect &&
212 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
216 rm -f heads head untracked &&
217 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
218 test_cmp expect heads &&
219 test_cmp expect head &&
220 test_cmp empty untracked
223 test_expect_success 'submodule add with // in path' '
224 echo "refs/heads/master" >expect &&
229 git submodule add "$submodurl" slashslashsubmod///frotz// &&
233 rm -f heads head untracked &&
234 inspect addtest/slashslashsubmod/frotz ../../.. &&
235 test_cmp expect heads &&
236 test_cmp expect head &&
237 test_cmp empty untracked
240 test_expect_success 'submodule add with /.. in path' '
241 echo "refs/heads/master" >expect &&
246 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
250 rm -f heads head untracked &&
251 inspect addtest/realsubmod ../.. &&
252 test_cmp expect heads &&
253 test_cmp expect head &&
254 test_cmp empty untracked
257 test_expect_success 'submodule add with ./, /.. and // in path' '
258 echo "refs/heads/master" >expect &&
263 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
267 rm -f heads head untracked &&
268 inspect addtest/realsubmod2 ../.. &&
269 test_cmp expect heads &&
270 test_cmp expect head &&
271 test_cmp empty untracked
274 test_expect_success !CYGWIN 'submodule add with \\ in path' '
275 test_when_finished "rm -rf parent sub\\with\\backslash" &&
277 # Initialize a repo with a backslash in its name
278 git init sub\\with\\backslash &&
279 touch sub\\with\\backslash/empty.file &&
280 git -C sub\\with\\backslash add empty.file &&
281 git -C sub\\with\\backslash commit -m "Added empty.file" &&
283 # Add that repository as a submodule
285 git -C parent submodule add ../sub\\with\\backslash
288 test_expect_success 'submodule add in subdirectory' '
289 echo "refs/heads/master" >expect &&
295 git submodule add "$submodurl" ../realsubmod3 &&
299 rm -f heads head untracked &&
300 inspect addtest/realsubmod3 ../.. &&
301 test_cmp expect heads &&
302 test_cmp expect head &&
303 test_cmp empty untracked
306 test_expect_success 'submodule add in subdirectory with relative path should fail' '
309 test_must_fail git submodule add ../../ submod3 2>../../output.err
311 test_i18ngrep toplevel output.err
314 test_expect_success 'setup - add an example entry to .gitmodules' '
315 git config --file=.gitmodules submodule.example.url git://example.com/init.git
318 test_expect_success 'status should fail for unmapped paths' '
319 test_must_fail git submodule status
322 test_expect_success 'setup - map path in .gitmodules' '
323 cat <<\EOF >expect &&
324 [submodule "example"]
325 url = git://example.com/init.git
329 git config --file=.gitmodules submodule.example.path init &&
331 test_cmp expect .gitmodules
334 test_expect_success 'status should only print one line' '
335 git submodule status >lines &&
336 test_line_count = 1 lines
339 test_expect_success 'setup - fetch commit name from submodule' '
340 rev1=$(cd .subrepo && git rev-parse HEAD) &&
341 printf "rev1: %s\n" "$rev1" &&
345 test_expect_success 'status should initially be "missing"' '
346 git submodule status >lines &&
350 test_expect_success 'init should register submodule url in .git/config' '
351 echo git://example.com/init.git >expect &&
353 git submodule init &&
354 git config submodule.example.url >url &&
355 git config submodule.example.url ./.subrepo &&
360 test_failure_with_unknown_submodule () {
361 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
362 grep "^error: .*no-such-submodule" output.err
365 test_expect_success 'init should fail with unknown submodule' '
366 test_failure_with_unknown_submodule init
369 test_expect_success 'update should fail with unknown submodule' '
370 test_failure_with_unknown_submodule update
373 test_expect_success 'status should fail with unknown submodule' '
374 test_failure_with_unknown_submodule status
377 test_expect_success 'sync should fail with unknown submodule' '
378 test_failure_with_unknown_submodule sync
381 test_expect_success 'update should fail when path is used by a file' '
382 echo hello >expect &&
384 echo "hello" >init &&
385 test_must_fail git submodule update &&
390 test_expect_success 'update should fail when path is used by a nonempty directory' '
391 echo hello >expect &&
395 echo "hello" >init/a &&
397 test_must_fail git submodule update &&
399 test_cmp expect init/a
402 test_expect_success 'update should work when path is an empty dir' '
405 echo "$rev1" >expect &&
408 git submodule update -q >update.out &&
409 test_must_be_empty update.out &&
412 test_cmp expect head-sha1
415 test_expect_success 'status should be "up-to-date" after update' '
416 git submodule status >list &&
420 test_expect_success 'status "up-to-date" from subdirectory' '
424 git submodule status >../list
426 grep "^ $rev1" list &&
427 grep "\\.\\./init" list
430 test_expect_success 'status "up-to-date" from subdirectory with path' '
434 git submodule status ../init >../list
436 grep "^ $rev1" list &&
437 grep "\\.\\./init" list
440 test_expect_success 'status should be "modified" after submodule commit' '
445 git commit -m "submodule commit 2"
448 rev2=$(cd init && git rev-parse HEAD) &&
450 git submodule status >list &&
455 test_expect_success 'the --cached sha1 should be rev1' '
456 git submodule --cached status >list &&
460 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
462 grep "^+Subproject commit $rev2" diff
465 test_expect_success 'update should checkout rev1' '
467 echo "$rev1" >expect &&
469 git submodule update init &&
472 test_cmp expect head-sha1
475 test_expect_success 'status should be "up-to-date" after update' '
476 git submodule status >list &&
480 test_expect_success 'checkout superproject with subproject already present' '
481 git checkout initial &&
485 test_expect_success 'apply submodule diff' '
493 git commit -m "change subproject"
495 git update-index --add init &&
496 git commit -m "change init" &&
497 git format-patch -1 --stdout >P.diff &&
498 git checkout second &&
499 git apply --index P.diff &&
501 git diff --cached master >staged &&
502 test_cmp empty staged
505 test_expect_success 'update --init' '
507 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
508 git config --remove-section submodule.example &&
509 test_must_fail git config submodule.example.url &&
511 git submodule update init 2> update.out &&
513 test_i18ngrep "not initialized" update.out &&
514 test_must_fail git rev-parse --resolve-git-dir init/.git &&
516 git submodule update --init init &&
517 git rev-parse --resolve-git-dir init/.git
520 test_expect_success 'update --init from subdirectory' '
522 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
523 git config --remove-section submodule.example &&
524 test_must_fail git config submodule.example.url &&
529 git submodule update ../init 2>update.out &&
531 test_i18ngrep "not initialized" update.out &&
532 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
534 git submodule update --init ../init
536 git rev-parse --resolve-git-dir init/.git
539 test_expect_success 'do not add files from a submodule' '
542 test_must_fail git add init/a
546 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
549 git commit -m "commit subproject" init &&
553 git diff --exit-code --cached init &&
555 git commit -m update a >/dev/null &&
556 git rev-parse HEAD) &&
558 test_must_fail git diff --exit-code --cached init &&
559 test $commit = $(git ls-files --stage |
560 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
562 git diff --exit-code --cached init
566 test_expect_success 'ls-files gracefully handles trailing slash' '
568 test "init" = "$(git ls-files init/)"
572 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
576 git checkout initial &&
581 test_expect_success 'submodule <invalid-subcommand> fails' '
582 test_must_fail git submodule no-such-subcommand
585 test_expect_success 'add submodules without specifying an explicit path' '
592 git commit -m "repo commit 1"
594 git clone --bare repo/ bare.git &&
597 git submodule add "$submodurl/repo" &&
598 git config -f .gitmodules submodule.repo.path repo &&
599 git submodule add "$submodurl/bare.git" &&
600 git config -f .gitmodules submodule.bare.path bare
604 test_expect_success 'add should fail when path is used by a file' '
608 test_must_fail git submodule add "$submodurl/repo" file
612 test_expect_success 'add should fail when path is used by an existing directory' '
616 test_must_fail git submodule add "$submodurl/repo" empty-dir
620 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
623 git submodule add ../repo relative &&
624 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
625 git submodule sync relative &&
626 test "$(git config submodule.relative.url)" = "$submodurl/repo"
630 test_expect_success 'set up for relative path tests' '
642 git config -f .gitmodules submodule.sub.path sub &&
643 git config -f .gitmodules submodule.sub.url ../subrepo &&
644 cp .git/config pristine-.git-config &&
645 cp .gitmodules pristine-.gitmodules
649 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
652 cp pristine-.git-config .git/config &&
653 cp pristine-.gitmodules .gitmodules &&
654 git config remote.origin.url ssh://hostname/repo &&
655 git submodule init &&
656 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
660 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
663 cp pristine-.git-config .git/config &&
664 cp pristine-.gitmodules .gitmodules &&
665 git config remote.origin.url ssh://hostname:22/repo &&
666 git submodule init &&
667 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
671 # About the choice of the path in the next test:
672 # - double-slash side-steps path mangling issues on Windows
673 # - it is still an absolute local path
674 # - there cannot be a server with a blank in its name just in case the
675 # path is used erroneously to access a //server/share style path
676 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
679 cp pristine-.git-config .git/config &&
680 cp pristine-.gitmodules .gitmodules &&
681 git config remote.origin.url "//somewhere else/repo" &&
682 git submodule init &&
683 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
687 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
690 cp pristine-.git-config .git/config &&
691 cp pristine-.gitmodules .gitmodules &&
692 git config remote.origin.url file:///tmp/repo &&
693 git submodule init &&
694 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
698 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
701 cp pristine-.git-config .git/config &&
702 cp pristine-.gitmodules .gitmodules &&
703 git config remote.origin.url helper:://hostname/repo &&
704 git submodule init &&
705 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
709 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
712 cp pristine-.git-config .git/config &&
713 git config remote.origin.url user@host:repo &&
714 git submodule init &&
715 test "$(git config submodule.sub.url)" = user@host:subrepo
719 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
722 cp pristine-.git-config .git/config &&
723 cp pristine-.gitmodules .gitmodules &&
724 git config remote.origin.url user@host:path/to/repo &&
725 git submodule init &&
726 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
730 test_expect_success '../subrepo works with relative local path - foo' '
733 cp pristine-.git-config .git/config &&
734 cp pristine-.gitmodules .gitmodules &&
735 git config remote.origin.url foo &&
736 # actual: fails with an error
737 git submodule init &&
738 test "$(git config submodule.sub.url)" = subrepo
742 test_expect_success '../subrepo works with relative local path - foo/bar' '
745 cp pristine-.git-config .git/config &&
746 cp pristine-.gitmodules .gitmodules &&
747 git config remote.origin.url foo/bar &&
748 git submodule init &&
749 test "$(git config submodule.sub.url)" = foo/subrepo
753 test_expect_success '../subrepo works with relative local path - ./foo' '
756 cp pristine-.git-config .git/config &&
757 cp pristine-.gitmodules .gitmodules &&
758 git config remote.origin.url ./foo &&
759 git submodule init &&
760 test "$(git config submodule.sub.url)" = subrepo
764 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
767 cp pristine-.git-config .git/config &&
768 cp pristine-.gitmodules .gitmodules &&
769 git config remote.origin.url ./foo/bar &&
770 git submodule init &&
771 test "$(git config submodule.sub.url)" = foo/subrepo
775 test_expect_success '../subrepo works with relative local path - ../foo' '
778 cp pristine-.git-config .git/config &&
779 cp pristine-.gitmodules .gitmodules &&
780 git config remote.origin.url ../foo &&
781 git submodule init &&
782 test "$(git config submodule.sub.url)" = ../subrepo
786 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
789 cp pristine-.git-config .git/config &&
790 cp pristine-.gitmodules .gitmodules &&
791 git config remote.origin.url ../foo/bar &&
792 git submodule init &&
793 test "$(git config submodule.sub.url)" = ../foo/subrepo
797 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
800 cp pristine-.git-config .git/config &&
801 cp pristine-.gitmodules .gitmodules &&
803 (cd a/b/c; git init) &&
804 git config remote.origin.url ../foo/bar.git &&
805 git submodule add ../bar/a/b/c ./a/b/c &&
806 git submodule init &&
807 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
811 test_expect_success 'moving the superproject does not break submodules' '
814 git submodule status >expect
816 mv addtest addtest2 &&
819 git submodule status >actual &&
820 test_cmp expect actual
824 test_expect_success 'moving the submodule does not break the superproject' '
829 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
830 mv addtest2/repo addtest2/repo.bak &&
831 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
836 test_cmp expect actual
839 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
844 echo "$submodurl/repo" >expect &&
845 git config remote.origin.url >actual &&
846 test_cmp expect actual &&
847 echo "gitdir: ../.git/modules/repo" >expect &&
852 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
853 test_must_be_empty actual &&
854 echo "gitdir: ../.git/modules/submod" >expect &&
855 test_cmp expect submod/.git &&
858 echo "$submodurl/bare.git" >expect &&
859 git config remote.origin.url >actual &&
860 test_cmp expect actual &&
861 echo "gitdir: ../.git/modules/repo_new" >expect &&
864 echo "repo" >expect &&
865 test_must_fail git config -f .gitmodules submodule.repo.path &&
866 git config -f .gitmodules submodule.repo_new.path >actual &&
867 test_cmp expect actual&&
868 echo "$submodurl/repo" >expect &&
869 test_must_fail git config -f .gitmodules submodule.repo.url &&
870 echo "$submodurl/bare.git" >expect &&
871 git config -f .gitmodules submodule.repo_new.url >actual &&
872 test_cmp expect actual &&
873 echo "$submodurl/repo" >expect &&
874 git config submodule.repo.url >actual &&
875 test_cmp expect actual &&
876 echo "$submodurl/bare.git" >expect &&
877 git config submodule.repo_new.url >actual &&
878 test_cmp expect actual
882 test_expect_success 'recursive relative submodules stay relative' '
883 test_when_finished "rm -rf super clone2 subsub sub3" &&
890 git commit -m "initial commit"
898 git commit -m "initial commit" &&
899 git submodule add ../subsub dirdir/subsub &&
900 git commit -m "add submodule subsub"
908 git commit -m "initial commit" &&
909 git submodule add ../sub3 &&
910 git commit -m "add submodule sub"
912 git clone super clone2 &&
915 git submodule update --init --recursive &&
916 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
917 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
919 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
920 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
923 test_expect_success 'submodule add with an existing name fails unless forced' '
928 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
930 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
931 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
932 echo "$submodurl/bare.git" >expect &&
933 git config submodule.repo_new.url >actual &&
934 test_cmp expect actual &&
935 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
937 echo "repo" >expect &&
938 git config -f .gitmodules submodule.repo_new.path >actual &&
939 test_cmp expect actual&&
940 echo "$submodurl/repo.git" >expect &&
941 git config -f .gitmodules submodule.repo_new.url >actual &&
942 test_cmp expect actual &&
943 echo "$submodurl/repo.git" >expect &&
944 git config submodule.repo_new.url >actual &&
945 test_cmp expect actual
949 test_expect_success 'set up a second submodule' '
950 git submodule add ./init2 example2 &&
951 git commit -m "submodule example2 added"
954 test_expect_success 'submodule deinit works on repository without submodules' '
955 test_when_finished "rm -rf newdirectory" &&
956 mkdir newdirectory &&
962 git commit -m "repo should not be empty" &&
963 git submodule deinit . &&
964 git submodule deinit --all
968 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
969 git config submodule.example.foo bar &&
970 git config submodule.example2.frotz nitfol &&
971 git submodule deinit init &&
972 test -z "$(git config --get-regexp "submodule\.example\.")" &&
973 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
974 test -f example2/.git &&
978 test_expect_success 'submodule deinit from subdirectory' '
979 git submodule update --init &&
980 git config submodule.example.foo bar &&
984 git submodule deinit ../init >../output
986 test_i18ngrep "\\.\\./init" output &&
987 test -z "$(git config --get-regexp "submodule\.example\.")" &&
988 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
989 test -f example2/.git &&
993 test_expect_success 'submodule deinit . deinits all initialized submodules' '
994 git submodule update --init &&
995 git config submodule.example.foo bar &&
996 git config submodule.example2.frotz nitfol &&
997 test_must_fail git submodule deinit &&
998 git submodule deinit . >actual &&
999 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1000 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1001 test_i18ngrep "Cleared directory .init" actual &&
1002 test_i18ngrep "Cleared directory .example2" actual &&
1006 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
1007 git submodule update --init &&
1008 git config submodule.example.foo bar &&
1009 git config submodule.example2.frotz nitfol &&
1010 test_must_fail git submodule deinit &&
1011 git submodule deinit --all >actual &&
1012 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1013 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1014 test_i18ngrep "Cleared directory .init" actual &&
1015 test_i18ngrep "Cleared directory .example2" actual &&
1019 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
1020 git submodule update --init &&
1021 rm -rf init example2/* example2/.git &&
1022 git submodule deinit init example2 >actual &&
1023 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1024 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1025 test_i18ngrep ! "Cleared directory .init" actual &&
1026 test_i18ngrep "Cleared directory .example2" actual &&
1030 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
1031 git submodule update --init &&
1033 test_must_fail git submodule deinit init &&
1034 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1035 test -f example2/.git &&
1036 git submodule deinit -f init >actual &&
1037 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1038 test_i18ngrep "Cleared directory .init" actual &&
1042 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
1043 git submodule update --init &&
1044 echo X >>init/untracked &&
1045 test_must_fail git submodule deinit init &&
1046 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1047 test -f example2/.git &&
1048 git submodule deinit -f init >actual &&
1049 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1050 test_i18ngrep "Cleared directory .init" actual &&
1054 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1055 git submodule update --init &&
1060 test_must_fail git submodule deinit init &&
1061 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1062 test -f example2/.git &&
1063 git submodule deinit -f init >actual &&
1064 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1065 test_i18ngrep "Cleared directory .init" actual &&
1069 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1070 git submodule update --init &&
1071 git submodule deinit init >actual &&
1072 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1073 test_i18ngrep "Cleared directory .init" actual &&
1074 git submodule deinit init >actual &&
1075 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1076 test_i18ngrep "Cleared directory .init" actual &&
1077 git submodule deinit . >actual &&
1078 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1079 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1080 test_i18ngrep "Cleared directory .init" actual &&
1081 git submodule deinit . >actual &&
1082 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1083 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1084 test_i18ngrep "Cleared directory .init" actual &&
1085 git submodule deinit --all >actual &&
1086 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1087 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1088 test_i18ngrep "Cleared directory .init" actual &&
1092 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1093 git submodule update --init &&
1097 cp -R ../.git/modules/example .git &&
1098 GIT_WORK_TREE=. git config --unset core.worktree
1100 test_must_fail git submodule deinit init &&
1101 test_must_fail git submodule deinit -f init &&
1102 test -d init/.git &&
1103 test -n "$(git config --get-regexp "submodule\.example\.")"
1106 test_expect_success 'submodule with UTF-8 name' '
1107 svname=$(printf "\303\245 \303\244\303\266") &&
1114 git commit -m "init sub"
1116 git submodule add ./"$svname" &&
1117 git submodule >&2 &&
1118 test -n "$(git submodule | grep "$svname")"
1121 test_expect_success 'submodule add clone shallow submodule' '
1127 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1130 test 1 = $(git log --oneline | wc -l)
1135 test_expect_success 'submodule helper list is not confused by common prefixes' '
1140 echo hi >testfile2 &&
1142 git commit -m "test1"
1148 echo hello >testfile1 &&
1150 git commit -m "test2"
1152 git submodule add /dir1/b dir1/b &&
1153 git submodule add /dir2/b dir2/b &&
1154 git commit -m "first submodule commit" &&
1155 git submodule--helper list dir1/b |cut -c51- >actual &&
1156 echo "dir1/b" >expect &&
1157 test_cmp expect actual
1160 test_expect_success 'setup superproject with submodules' '
1162 test_commit -C sub1 test &&
1163 test_commit -C sub1 test2 &&
1164 git init multisuper &&
1165 git -C multisuper submodule add ../sub1 sub0 &&
1166 git -C multisuper submodule add ../sub1 sub1 &&
1167 git -C multisuper submodule add ../sub1 sub2 &&
1168 git -C multisuper submodule add ../sub1 sub3 &&
1169 git -C multisuper commit -m "add some submodules"
1179 test_expect_success 'submodule update --init with a specification' '
1180 test_when_finished "rm -rf multisuper_clone" &&
1182 git clone file://"$pwd"/multisuper multisuper_clone &&
1183 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1184 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1185 test_cmp expect actual
1188 test_expect_success 'submodule update --init with submodule.active set' '
1189 test_when_finished "rm -rf multisuper_clone" &&
1191 git clone file://"$pwd"/multisuper multisuper_clone &&
1192 git -C multisuper_clone config submodule.active "." &&
1193 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1194 git -C multisuper_clone submodule update --init &&
1195 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1196 test_cmp expect actual
1199 test_expect_success 'submodule update and setting submodule.<name>.active' '
1200 test_when_finished "rm -rf multisuper_clone" &&
1202 git clone file://"$pwd"/multisuper multisuper_clone &&
1203 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1204 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1205 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1207 cat >expect <<-\EOF &&
1213 git -C multisuper_clone submodule update &&
1214 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1215 test_cmp expect actual
1218 test_expect_success 'clone --recurse-submodules with a pathspec works' '
1219 test_when_finished "rm -rf multisuper_clone" &&
1220 cat >expected <<-\EOF &&
1227 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1228 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1229 test_cmp expected actual
1232 test_expect_success 'clone with multiple --recurse-submodules options' '
1233 test_when_finished "rm -rf multisuper_clone" &&
1234 cat >expect <<-\EOF &&
1241 git clone --recurse-submodules="." \
1242 --recurse-submodules=":(exclude)sub0" \
1243 --recurse-submodules=":(exclude)sub2" \
1244 multisuper multisuper_clone &&
1245 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1246 test_cmp expect actual
1249 test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
1250 test_when_finished "rm -rf multisuper_clone" &&
1251 cat <<-\EOF >expect &&
1258 cat <<-\EOF >expect2 &&
1267 git clone --recurse-submodules="." \
1268 --recurse-submodules=":(exclude)sub0" \
1269 --recurse-submodules=":(exclude)sub2" \
1270 --recurse-submodules=":(exclude)sub4" \
1271 multisuper multisuper_clone &&
1273 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1274 test_cmp expect actual &&
1276 git -C multisuper submodule add ../sub1 sub4 &&
1277 git -C multisuper submodule add ../sub1 sub5 &&
1278 git -C multisuper commit -m "add more submodules" &&
1279 # obtain the new superproject
1280 git -C multisuper_clone pull &&
1281 git -C multisuper_clone submodule update --init &&
1282 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1283 test_cmp expect2 actual
1286 test_expect_success 'init properly sets the config' '
1287 test_when_finished "rm -rf multisuper_clone" &&
1288 git clone --recurse-submodules="." \
1289 --recurse-submodules=":(exclude)sub0" \
1290 multisuper multisuper_clone &&
1292 git -C multisuper_clone submodule init -- sub0 sub1 &&
1293 git -C multisuper_clone config --get submodule.sub0.active &&
1294 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1297 test_expect_success 'recursive clone respects -q' '
1298 test_when_finished "rm -rf multisuper_clone" &&
1299 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1300 test_must_be_empty actual