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 'setup parent and one repository' '
130 test_create_repo parent &&
131 test_commit -C parent one
134 test_expect_success 'redirected submodule add does not show progress' '
135 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
138 test_i18ngrep ! "Checking connectivity" err
141 test_expect_success 'redirected submodule add --progress does show progress' '
142 git -C addtest submodule add --progress "file://$submodurl/parent" \
143 submod-redirected-progress 2>err && \
147 test_expect_success 'submodule add to .gitignored path fails' '
150 cat <<-\EOF >expect &&
151 The following path is ignored by one of your .gitignore files:
153 Use -f if you really want to add it.
155 # Does not use test_commit due to the ignore
156 echo "*" > .gitignore &&
157 git add --force .gitignore &&
158 git commit -m"Ignore everything" &&
159 ! git submodule add "$submodurl" submod >actual 2>&1 &&
160 test_i18ncmp expect actual
164 test_expect_success 'submodule add to .gitignored path with --force' '
167 git submodule add --force "$submodurl" submod
171 test_expect_success 'submodule add to reconfigure existing submodule with --force' '
174 git submodule add --force bogus-url submod &&
175 git submodule add -b initial "$submodurl" submod-branch &&
176 test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
177 test "bogus-url" = "$(git config submodule.submod.url)" &&
179 git submodule add --force "$submodurl" submod
180 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
181 test "$submodurl" = "$(git config submodule.submod.url)"
185 test_expect_success 'submodule add --branch' '
186 echo "refs/heads/initial" >expect-head &&
187 cat <<-\EOF >expect-heads &&
195 git submodule add -b initial "$submodurl" submod-branch &&
196 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
200 rm -f heads head untracked &&
201 inspect addtest/submod-branch ../.. &&
202 test_cmp expect-heads heads &&
203 test_cmp expect-head head &&
204 test_cmp empty untracked
207 test_expect_success 'submodule add with ./ in path' '
208 echo "refs/heads/master" >expect &&
213 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
217 rm -f heads head untracked &&
218 inspect addtest/dotsubmod/frotz ../../.. &&
219 test_cmp expect heads &&
220 test_cmp expect head &&
221 test_cmp empty untracked
224 test_expect_success 'submodule add with /././ in path' '
225 echo "refs/heads/master" >expect &&
230 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
234 rm -f heads head untracked &&
235 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
236 test_cmp expect heads &&
237 test_cmp expect head &&
238 test_cmp empty untracked
241 test_expect_success 'submodule add with // in path' '
242 echo "refs/heads/master" >expect &&
247 git submodule add "$submodurl" slashslashsubmod///frotz// &&
251 rm -f heads head untracked &&
252 inspect addtest/slashslashsubmod/frotz ../../.. &&
253 test_cmp expect heads &&
254 test_cmp expect head &&
255 test_cmp empty untracked
258 test_expect_success 'submodule add with /.. in path' '
259 echo "refs/heads/master" >expect &&
264 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
268 rm -f heads head untracked &&
269 inspect addtest/realsubmod ../.. &&
270 test_cmp expect heads &&
271 test_cmp expect head &&
272 test_cmp empty untracked
275 test_expect_success 'submodule add with ./, /.. and // in path' '
276 echo "refs/heads/master" >expect &&
281 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
285 rm -f heads head untracked &&
286 inspect addtest/realsubmod2 ../.. &&
287 test_cmp expect heads &&
288 test_cmp expect head &&
289 test_cmp empty untracked
292 test_expect_success !CYGWIN 'submodule add with \\ in path' '
293 test_when_finished "rm -rf parent sub\\with\\backslash" &&
295 # Initialize a repo with a backslash in its name
296 git init sub\\with\\backslash &&
297 touch sub\\with\\backslash/empty.file &&
298 git -C sub\\with\\backslash add empty.file &&
299 git -C sub\\with\\backslash commit -m "Added empty.file" &&
301 # Add that repository as a submodule
303 git -C parent submodule add ../sub\\with\\backslash
306 test_expect_success 'submodule add in subdirectory' '
307 echo "refs/heads/master" >expect &&
313 git submodule add "$submodurl" ../realsubmod3 &&
317 rm -f heads head untracked &&
318 inspect addtest/realsubmod3 ../.. &&
319 test_cmp expect heads &&
320 test_cmp expect head &&
321 test_cmp empty untracked
324 test_expect_success 'submodule add in subdirectory with relative path should fail' '
327 test_must_fail git submodule add ../../ submod3 2>../../output.err
329 test_i18ngrep toplevel output.err
332 test_expect_success 'setup - add an example entry to .gitmodules' '
333 git config --file=.gitmodules submodule.example.url git://example.com/init.git
336 test_expect_success 'status should fail for unmapped paths' '
337 test_must_fail git submodule status
340 test_expect_success 'setup - map path in .gitmodules' '
341 cat <<\EOF >expect &&
342 [submodule "example"]
343 url = git://example.com/init.git
347 git config --file=.gitmodules submodule.example.path init &&
349 test_cmp expect .gitmodules
352 test_expect_success 'status should only print one line' '
353 git submodule status >lines &&
354 test_line_count = 1 lines
357 test_expect_success 'setup - fetch commit name from submodule' '
358 rev1=$(cd .subrepo && git rev-parse HEAD) &&
359 printf "rev1: %s\n" "$rev1" &&
363 test_expect_success 'status should initially be "missing"' '
364 git submodule status >lines &&
368 test_expect_success 'init should register submodule url in .git/config' '
369 echo git://example.com/init.git >expect &&
371 git submodule init &&
372 git config submodule.example.url >url &&
373 git config submodule.example.url ./.subrepo &&
378 test_failure_with_unknown_submodule () {
379 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
380 grep "^error: .*no-such-submodule" output.err
383 test_expect_success 'init should fail with unknown submodule' '
384 test_failure_with_unknown_submodule init
387 test_expect_success 'update should fail with unknown submodule' '
388 test_failure_with_unknown_submodule update
391 test_expect_success 'status should fail with unknown submodule' '
392 test_failure_with_unknown_submodule status
395 test_expect_success 'sync should fail with unknown submodule' '
396 test_failure_with_unknown_submodule sync
399 test_expect_success 'update should fail when path is used by a file' '
400 echo hello >expect &&
402 echo "hello" >init &&
403 test_must_fail git submodule update &&
408 test_expect_success 'update should fail when path is used by a nonempty directory' '
409 echo hello >expect &&
413 echo "hello" >init/a &&
415 test_must_fail git submodule update &&
417 test_cmp expect init/a
420 test_expect_success 'update should work when path is an empty dir' '
423 echo "$rev1" >expect &&
426 git submodule update -q >update.out &&
427 test_must_be_empty update.out &&
430 test_cmp expect head-sha1
433 test_expect_success 'status should be "up-to-date" after update' '
434 git submodule status >list &&
438 test_expect_success 'status "up-to-date" from subdirectory' '
442 git submodule status >../list
444 grep "^ $rev1" list &&
445 grep "\\.\\./init" list
448 test_expect_success 'status "up-to-date" from subdirectory with path' '
452 git submodule status ../init >../list
454 grep "^ $rev1" list &&
455 grep "\\.\\./init" list
458 test_expect_success 'status should be "modified" after submodule commit' '
463 git commit -m "submodule commit 2"
466 rev2=$(cd init && git rev-parse HEAD) &&
468 git submodule status >list &&
473 test_expect_success 'the --cached sha1 should be rev1' '
474 git submodule --cached status >list &&
478 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
480 grep "^+Subproject commit $rev2" diff
483 test_expect_success 'update should checkout rev1' '
485 echo "$rev1" >expect &&
487 git submodule update init &&
490 test_cmp expect head-sha1
493 test_expect_success 'status should be "up-to-date" after update' '
494 git submodule status >list &&
498 test_expect_success 'checkout superproject with subproject already present' '
499 git checkout initial &&
503 test_expect_success 'apply submodule diff' '
511 git commit -m "change subproject"
513 git update-index --add init &&
514 git commit -m "change init" &&
515 git format-patch -1 --stdout >P.diff &&
516 git checkout second &&
517 git apply --index P.diff &&
519 git diff --cached master >staged &&
520 test_cmp empty staged
523 test_expect_success 'update --init' '
525 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
526 git config --remove-section submodule.example &&
527 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 &&
535 git rev-parse --resolve-git-dir init/.git
538 test_expect_success 'update --init from subdirectory' '
540 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
541 git config --remove-section submodule.example &&
542 test_must_fail git config submodule.example.url &&
547 git submodule update ../init 2>update.out &&
549 test_i18ngrep "not initialized" update.out &&
550 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
552 git submodule update --init ../init
554 git rev-parse --resolve-git-dir init/.git
557 test_expect_success 'do not add files from a submodule' '
560 test_must_fail git add init/a
564 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
567 git commit -m "commit subproject" init &&
571 git diff --exit-code --cached init &&
573 git commit -m update a >/dev/null &&
574 git rev-parse HEAD) &&
576 test_must_fail git diff --exit-code --cached init &&
577 test $commit = $(git ls-files --stage |
578 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
580 git diff --exit-code --cached init
584 test_expect_success 'ls-files gracefully handles trailing slash' '
586 test "init" = "$(git ls-files init/)"
590 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
594 git checkout initial &&
599 test_expect_success 'submodule <invalid-subcommand> fails' '
600 test_must_fail git submodule no-such-subcommand
603 test_expect_success 'add submodules without specifying an explicit path' '
610 git commit -m "repo commit 1"
612 git clone --bare repo/ bare.git &&
615 git submodule add "$submodurl/repo" &&
616 git config -f .gitmodules submodule.repo.path repo &&
617 git submodule add "$submodurl/bare.git" &&
618 git config -f .gitmodules submodule.bare.path bare
622 test_expect_success 'add should fail when path is used by a file' '
626 test_must_fail git submodule add "$submodurl/repo" file
630 test_expect_success 'add should fail when path is used by an existing directory' '
634 test_must_fail git submodule add "$submodurl/repo" empty-dir
638 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
641 git submodule add ../repo relative &&
642 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
643 git submodule sync relative &&
644 test "$(git config submodule.relative.url)" = "$submodurl/repo"
648 test_expect_success 'set up for relative path tests' '
660 git config -f .gitmodules submodule.sub.path sub &&
661 git config -f .gitmodules submodule.sub.url ../subrepo &&
662 cp .git/config pristine-.git-config &&
663 cp .gitmodules pristine-.gitmodules
667 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
670 cp pristine-.git-config .git/config &&
671 cp pristine-.gitmodules .gitmodules &&
672 git config remote.origin.url ssh://hostname/repo &&
673 git submodule init &&
674 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
678 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
681 cp pristine-.git-config .git/config &&
682 cp pristine-.gitmodules .gitmodules &&
683 git config remote.origin.url ssh://hostname:22/repo &&
684 git submodule init &&
685 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
689 # About the choice of the path in the next test:
690 # - double-slash side-steps path mangling issues on Windows
691 # - it is still an absolute local path
692 # - there cannot be a server with a blank in its name just in case the
693 # path is used erroneously to access a //server/share style path
694 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
697 cp pristine-.git-config .git/config &&
698 cp pristine-.gitmodules .gitmodules &&
699 git config remote.origin.url "//somewhere else/repo" &&
700 git submodule init &&
701 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
705 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
708 cp pristine-.git-config .git/config &&
709 cp pristine-.gitmodules .gitmodules &&
710 git config remote.origin.url file:///tmp/repo &&
711 git submodule init &&
712 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
716 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
719 cp pristine-.git-config .git/config &&
720 cp pristine-.gitmodules .gitmodules &&
721 git config remote.origin.url helper:://hostname/repo &&
722 git submodule init &&
723 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
727 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
730 cp pristine-.git-config .git/config &&
731 git config remote.origin.url user@host:repo &&
732 git submodule init &&
733 test "$(git config submodule.sub.url)" = user@host:subrepo
737 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
740 cp pristine-.git-config .git/config &&
741 cp pristine-.gitmodules .gitmodules &&
742 git config remote.origin.url user@host:path/to/repo &&
743 git submodule init &&
744 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
748 test_expect_success '../subrepo works with relative local path - foo' '
751 cp pristine-.git-config .git/config &&
752 cp pristine-.gitmodules .gitmodules &&
753 git config remote.origin.url foo &&
754 # actual: fails with an error
755 git submodule init &&
756 test "$(git config submodule.sub.url)" = subrepo
760 test_expect_success '../subrepo works with relative local path - foo/bar' '
763 cp pristine-.git-config .git/config &&
764 cp pristine-.gitmodules .gitmodules &&
765 git config remote.origin.url foo/bar &&
766 git submodule init &&
767 test "$(git config submodule.sub.url)" = foo/subrepo
771 test_expect_success '../subrepo works with relative local path - ./foo' '
774 cp pristine-.git-config .git/config &&
775 cp pristine-.gitmodules .gitmodules &&
776 git config remote.origin.url ./foo &&
777 git submodule init &&
778 test "$(git config submodule.sub.url)" = subrepo
782 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
785 cp pristine-.git-config .git/config &&
786 cp pristine-.gitmodules .gitmodules &&
787 git config remote.origin.url ./foo/bar &&
788 git submodule init &&
789 test "$(git config submodule.sub.url)" = foo/subrepo
793 test_expect_success '../subrepo works with relative local path - ../foo' '
796 cp pristine-.git-config .git/config &&
797 cp pristine-.gitmodules .gitmodules &&
798 git config remote.origin.url ../foo &&
799 git submodule init &&
800 test "$(git config submodule.sub.url)" = ../subrepo
804 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
807 cp pristine-.git-config .git/config &&
808 cp pristine-.gitmodules .gitmodules &&
809 git config remote.origin.url ../foo/bar &&
810 git submodule init &&
811 test "$(git config submodule.sub.url)" = ../foo/subrepo
815 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
818 cp pristine-.git-config .git/config &&
819 cp pristine-.gitmodules .gitmodules &&
821 (cd a/b/c; git init) &&
822 git config remote.origin.url ../foo/bar.git &&
823 git submodule add ../bar/a/b/c ./a/b/c &&
824 git submodule init &&
825 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
829 test_expect_success 'moving the superproject does not break submodules' '
832 git submodule status >expect
834 mv addtest addtest2 &&
837 git submodule status >actual &&
838 test_cmp expect actual
842 test_expect_success 'moving the submodule does not break the superproject' '
847 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
848 mv addtest2/repo addtest2/repo.bak &&
849 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
854 test_cmp expect actual
857 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
862 echo "$submodurl/repo" >expect &&
863 git config remote.origin.url >actual &&
864 test_cmp expect actual &&
865 echo "gitdir: ../.git/modules/repo" >expect &&
870 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
871 test_must_be_empty actual &&
872 echo "gitdir: ../.git/modules/submod" >expect &&
873 test_cmp expect submod/.git &&
876 echo "$submodurl/bare.git" >expect &&
877 git config remote.origin.url >actual &&
878 test_cmp expect actual &&
879 echo "gitdir: ../.git/modules/repo_new" >expect &&
882 echo "repo" >expect &&
883 test_must_fail git config -f .gitmodules submodule.repo.path &&
884 git config -f .gitmodules submodule.repo_new.path >actual &&
885 test_cmp expect actual&&
886 echo "$submodurl/repo" >expect &&
887 test_must_fail git config -f .gitmodules submodule.repo.url &&
888 echo "$submodurl/bare.git" >expect &&
889 git config -f .gitmodules submodule.repo_new.url >actual &&
890 test_cmp expect actual &&
891 echo "$submodurl/repo" >expect &&
892 git config submodule.repo.url >actual &&
893 test_cmp expect actual &&
894 echo "$submodurl/bare.git" >expect &&
895 git config submodule.repo_new.url >actual &&
896 test_cmp expect actual
900 test_expect_success 'recursive relative submodules stay relative' '
901 test_when_finished "rm -rf super clone2 subsub sub3" &&
908 git commit -m "initial commit"
916 git commit -m "initial commit" &&
917 git submodule add ../subsub dirdir/subsub &&
918 git commit -m "add submodule subsub"
926 git commit -m "initial commit" &&
927 git submodule add ../sub3 &&
928 git commit -m "add submodule sub"
930 git clone super clone2 &&
933 git submodule update --init --recursive &&
934 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
935 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
937 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
938 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
941 test_expect_success 'submodule add with an existing name fails unless forced' '
946 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
948 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
949 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
950 echo "$submodurl/bare.git" >expect &&
951 git config submodule.repo_new.url >actual &&
952 test_cmp expect actual &&
953 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
955 echo "repo" >expect &&
956 git config -f .gitmodules submodule.repo_new.path >actual &&
957 test_cmp expect actual&&
958 echo "$submodurl/repo.git" >expect &&
959 git config -f .gitmodules submodule.repo_new.url >actual &&
960 test_cmp expect actual &&
961 echo "$submodurl/repo.git" >expect &&
962 git config submodule.repo_new.url >actual &&
963 test_cmp expect actual
967 test_expect_success 'set up a second submodule' '
968 git submodule add ./init2 example2 &&
969 git commit -m "submodule example2 added"
972 test_expect_success 'submodule deinit works on repository without submodules' '
973 test_when_finished "rm -rf newdirectory" &&
974 mkdir newdirectory &&
980 git commit -m "repo should not be empty" &&
981 git submodule deinit . &&
982 git submodule deinit --all
986 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
987 git config submodule.example.foo bar &&
988 git config submodule.example2.frotz nitfol &&
989 git submodule deinit init &&
990 test -z "$(git config --get-regexp "submodule\.example\.")" &&
991 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
992 test -f example2/.git &&
996 test_expect_success 'submodule deinit should unset core.worktree' '
997 test_path_is_file .git/modules/example/config &&
998 test_must_fail git config -f .git/modules/example/config core.worktree
1001 test_expect_success 'submodule deinit from subdirectory' '
1002 git submodule update --init &&
1003 git config submodule.example.foo bar &&
1007 git submodule deinit ../init >../output
1009 test_i18ngrep "\\.\\./init" output &&
1010 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1011 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1012 test -f example2/.git &&
1016 test_expect_success 'submodule deinit . deinits all initialized submodules' '
1017 git submodule update --init &&
1018 git config submodule.example.foo bar &&
1019 git config submodule.example2.frotz nitfol &&
1020 test_must_fail git submodule deinit &&
1021 git submodule deinit . >actual &&
1022 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1023 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1024 test_i18ngrep "Cleared directory .init" actual &&
1025 test_i18ngrep "Cleared directory .example2" actual &&
1029 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
1030 git submodule update --init &&
1031 git config submodule.example.foo bar &&
1032 git config submodule.example2.frotz nitfol &&
1033 test_must_fail git submodule deinit &&
1034 git submodule deinit --all >actual &&
1035 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1036 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1037 test_i18ngrep "Cleared directory .init" actual &&
1038 test_i18ngrep "Cleared directory .example2" actual &&
1042 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
1043 git submodule update --init &&
1044 rm -rf init example2/* example2/.git &&
1045 git submodule deinit init example2 >actual &&
1046 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1047 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1048 test_i18ngrep ! "Cleared directory .init" actual &&
1049 test_i18ngrep "Cleared directory .example2" actual &&
1053 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
1054 git submodule update --init &&
1056 test_must_fail git submodule deinit init &&
1057 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1058 test -f example2/.git &&
1059 git submodule deinit -f init >actual &&
1060 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1061 test_i18ngrep "Cleared directory .init" actual &&
1065 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
1066 git submodule update --init &&
1067 echo X >>init/untracked &&
1068 test_must_fail git submodule deinit init &&
1069 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1070 test -f example2/.git &&
1071 git submodule deinit -f init >actual &&
1072 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1073 test_i18ngrep "Cleared directory .init" actual &&
1077 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1078 git submodule update --init &&
1083 test_must_fail git submodule deinit init &&
1084 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1085 test -f example2/.git &&
1086 git submodule deinit -f init >actual &&
1087 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1088 test_i18ngrep "Cleared directory .init" actual &&
1092 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1093 git submodule update --init &&
1094 git submodule deinit init >actual &&
1095 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1096 test_i18ngrep "Cleared directory .init" actual &&
1097 git submodule deinit init >actual &&
1098 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1099 test_i18ngrep "Cleared directory .init" actual &&
1100 git submodule deinit . >actual &&
1101 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1102 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1103 test_i18ngrep "Cleared directory .init" actual &&
1104 git submodule deinit . >actual &&
1105 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1106 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1107 test_i18ngrep "Cleared directory .init" actual &&
1108 git submodule deinit --all >actual &&
1109 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1110 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1111 test_i18ngrep "Cleared directory .init" actual &&
1115 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1116 git submodule update --init &&
1120 cp -R ../.git/modules/example .git &&
1121 GIT_WORK_TREE=. git config --unset core.worktree
1123 test_must_fail git submodule deinit init &&
1124 test_must_fail git submodule deinit -f init &&
1125 test -d init/.git &&
1126 test -n "$(git config --get-regexp "submodule\.example\.")"
1129 test_expect_success 'submodule with UTF-8 name' '
1130 svname=$(printf "\303\245 \303\244\303\266") &&
1137 git commit -m "init sub"
1139 git submodule add ./"$svname" &&
1140 git submodule >&2 &&
1141 test -n "$(git submodule | grep "$svname")"
1144 test_expect_success 'submodule add clone shallow submodule' '
1150 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1153 test 1 = $(git log --oneline | wc -l)
1158 test_expect_success 'submodule helper list is not confused by common prefixes' '
1163 echo hi >testfile2 &&
1165 git commit -m "test1"
1171 echo hello >testfile1 &&
1173 git commit -m "test2"
1175 git submodule add /dir1/b dir1/b &&
1176 git submodule add /dir2/b dir2/b &&
1177 git commit -m "first submodule commit" &&
1178 git submodule--helper list dir1/b |cut -c51- >actual &&
1179 echo "dir1/b" >expect &&
1180 test_cmp expect actual
1183 test_expect_success 'setup superproject with submodules' '
1185 test_commit -C sub1 test &&
1186 test_commit -C sub1 test2 &&
1187 git init multisuper &&
1188 git -C multisuper submodule add ../sub1 sub0 &&
1189 git -C multisuper submodule add ../sub1 sub1 &&
1190 git -C multisuper submodule add ../sub1 sub2 &&
1191 git -C multisuper submodule add ../sub1 sub3 &&
1192 git -C multisuper commit -m "add some submodules"
1202 test_expect_success 'submodule update --init with a specification' '
1203 test_when_finished "rm -rf multisuper_clone" &&
1205 git clone file://"$pwd"/multisuper multisuper_clone &&
1206 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1207 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1208 test_cmp expect actual
1211 test_expect_success 'submodule update --init with submodule.active set' '
1212 test_when_finished "rm -rf multisuper_clone" &&
1214 git clone file://"$pwd"/multisuper multisuper_clone &&
1215 git -C multisuper_clone config submodule.active "." &&
1216 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1217 git -C multisuper_clone submodule update --init &&
1218 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1219 test_cmp expect actual
1222 test_expect_success 'submodule update and setting submodule.<name>.active' '
1223 test_when_finished "rm -rf multisuper_clone" &&
1225 git clone file://"$pwd"/multisuper multisuper_clone &&
1226 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1227 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1228 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1230 cat >expect <<-\EOF &&
1236 git -C multisuper_clone submodule update &&
1237 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1238 test_cmp expect actual
1241 test_expect_success 'clone --recurse-submodules with a pathspec works' '
1242 test_when_finished "rm -rf multisuper_clone" &&
1243 cat >expected <<-\EOF &&
1250 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1251 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1252 test_cmp expected actual
1255 test_expect_success 'clone with multiple --recurse-submodules options' '
1256 test_when_finished "rm -rf multisuper_clone" &&
1257 cat >expect <<-\EOF &&
1264 git clone --recurse-submodules="." \
1265 --recurse-submodules=":(exclude)sub0" \
1266 --recurse-submodules=":(exclude)sub2" \
1267 multisuper multisuper_clone &&
1268 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1269 test_cmp expect actual
1272 test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
1273 test_when_finished "rm -rf multisuper_clone" &&
1274 cat <<-\EOF >expect &&
1281 cat <<-\EOF >expect2 &&
1290 git clone --recurse-submodules="." \
1291 --recurse-submodules=":(exclude)sub0" \
1292 --recurse-submodules=":(exclude)sub2" \
1293 --recurse-submodules=":(exclude)sub4" \
1294 multisuper multisuper_clone &&
1296 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1297 test_cmp expect actual &&
1299 git -C multisuper submodule add ../sub1 sub4 &&
1300 git -C multisuper submodule add ../sub1 sub5 &&
1301 git -C multisuper commit -m "add more submodules" &&
1302 # obtain the new superproject
1303 git -C multisuper_clone pull &&
1304 git -C multisuper_clone submodule update --init &&
1305 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1306 test_cmp expect2 actual
1309 test_expect_success 'init properly sets the config' '
1310 test_when_finished "rm -rf multisuper_clone" &&
1311 git clone --recurse-submodules="." \
1312 --recurse-submodules=":(exclude)sub0" \
1313 multisuper multisuper_clone &&
1315 git -C multisuper_clone submodule init -- sub0 sub1 &&
1316 git -C multisuper_clone config --get submodule.sub0.active &&
1317 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1320 test_expect_success 'recursive clone respects -q' '
1321 test_when_finished "rm -rf multisuper_clone" &&
1322 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1323 test_must_be_empty actual