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 bogus_url="$(pwd)/bogus-url" &&
175 git submodule add --force "$bogus_url" submod &&
176 git submodule add --force -b initial "$submodurl" submod-branch &&
177 test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" &&
178 test "$bogus_url" = "$(git config submodule.submod.url)" &&
180 git submodule add --force "$submodurl" submod &&
181 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
182 test "$submodurl" = "$(git config submodule.submod.url)"
186 test_expect_success
'submodule add --branch' '
187 echo "refs/heads/initial" >expect-head &&
188 cat <<-\EOF >expect-heads &&
196 git submodule add -b initial "$submodurl" submod-branch &&
197 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
201 rm -f heads head untracked &&
202 inspect addtest/submod-branch ../.. &&
203 test_cmp expect-heads heads &&
204 test_cmp expect-head head &&
205 test_cmp empty untracked
208 test_expect_success
'submodule add with ./ in path' '
209 echo "refs/heads/master" >expect &&
214 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
218 rm -f heads head untracked &&
219 inspect addtest/dotsubmod/frotz ../../.. &&
220 test_cmp expect heads &&
221 test_cmp expect head &&
222 test_cmp empty untracked
225 test_expect_success
'submodule add with /././ in path' '
226 echo "refs/heads/master" >expect &&
231 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
235 rm -f heads head untracked &&
236 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
237 test_cmp expect heads &&
238 test_cmp expect head &&
239 test_cmp empty untracked
242 test_expect_success
'submodule add with // in path' '
243 echo "refs/heads/master" >expect &&
248 git submodule add "$submodurl" slashslashsubmod///frotz// &&
252 rm -f heads head untracked &&
253 inspect addtest/slashslashsubmod/frotz ../../.. &&
254 test_cmp expect heads &&
255 test_cmp expect head &&
256 test_cmp empty untracked
259 test_expect_success
'submodule add with /.. in path' '
260 echo "refs/heads/master" >expect &&
265 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
269 rm -f heads head untracked &&
270 inspect addtest/realsubmod ../.. &&
271 test_cmp expect heads &&
272 test_cmp expect head &&
273 test_cmp empty untracked
276 test_expect_success
'submodule add with ./, /.. and // in path' '
277 echo "refs/heads/master" >expect &&
282 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
286 rm -f heads head untracked &&
287 inspect addtest/realsubmod2 ../.. &&
288 test_cmp expect heads &&
289 test_cmp expect head &&
290 test_cmp empty untracked
293 test_expect_success
!CYGWIN
'submodule add with \\ in path' '
294 test_when_finished "rm -rf parent sub\\with\\backslash" &&
296 # Initialize a repo with a backslash in its name
297 git init sub\\with\\backslash &&
298 touch sub\\with\\backslash/empty.file &&
299 git -C sub\\with\\backslash add empty.file &&
300 git -C sub\\with\\backslash commit -m "Added empty.file" &&
302 # Add that repository as a submodule
304 git -C parent submodule add ../sub\\with\\backslash
307 test_expect_success
'submodule add in subdirectory' '
308 echo "refs/heads/master" >expect &&
314 git submodule add "$submodurl" ../realsubmod3 &&
318 rm -f heads head untracked &&
319 inspect addtest/realsubmod3 ../.. &&
320 test_cmp expect heads &&
321 test_cmp expect head &&
322 test_cmp empty untracked
325 test_expect_success
'submodule add in subdirectory with relative path should fail' '
328 test_must_fail git submodule add ../../ submod3 2>../../output.err
330 test_i18ngrep toplevel output.err
333 test_expect_success
'setup - add an example entry to .gitmodules' '
334 git config --file=.gitmodules submodule.example.url git://example.com/init.git
337 test_expect_success
'status should fail for unmapped paths' '
338 test_must_fail git submodule status
341 test_expect_success
'setup - map path in .gitmodules' '
342 cat <<\EOF >expect &&
343 [submodule "example"]
344 url = git://example.com/init.git
348 git config --file=.gitmodules submodule.example.path init &&
350 test_cmp expect .gitmodules
353 test_expect_success
'status should only print one line' '
354 git submodule status >lines &&
355 test_line_count = 1 lines
358 test_expect_success
'setup - fetch commit name from submodule' '
359 rev1=$(cd .subrepo && git rev-parse HEAD) &&
360 printf "rev1: %s\n" "$rev1" &&
364 test_expect_success
'status should initially be "missing"' '
365 git submodule status >lines &&
369 test_expect_success
'init should register submodule url in .git/config' '
370 echo git://example.com/init.git >expect &&
372 git submodule init &&
373 git config submodule.example.url >url &&
374 git config submodule.example.url ./.subrepo &&
379 test_failure_with_unknown_submodule
() {
380 test_must_fail git submodule
$1 no-such-submodule
2>output.err
&&
381 test_i18ngrep
"^error: .*no-such-submodule" output.err
384 test_expect_success
'init should fail with unknown submodule' '
385 test_failure_with_unknown_submodule init
388 test_expect_success
'update should fail with unknown submodule' '
389 test_failure_with_unknown_submodule update
392 test_expect_success
'status should fail with unknown submodule' '
393 test_failure_with_unknown_submodule status
396 test_expect_success
'sync should fail with unknown submodule' '
397 test_failure_with_unknown_submodule sync
400 test_expect_success
'update should fail when path is used by a file' '
401 echo hello >expect &&
403 echo "hello" >init &&
404 test_must_fail git submodule update &&
409 test_expect_success
'update should fail when path is used by a nonempty directory' '
410 echo hello >expect &&
414 echo "hello" >init/a &&
416 test_must_fail git submodule update &&
418 test_cmp expect init/a
421 test_expect_success
'update should work when path is an empty dir' '
424 echo "$rev1" >expect &&
427 git submodule update -q >update.out &&
428 test_must_be_empty update.out &&
431 test_cmp expect head-sha1
434 test_expect_success
'status should be "up-to-date" after update' '
435 git submodule status >list &&
439 test_expect_success
'status "up-to-date" from subdirectory' '
443 git submodule status >../list
445 grep "^ $rev1" list &&
446 grep "\\.\\./init" list
449 test_expect_success
'status "up-to-date" from subdirectory with path' '
453 git submodule status ../init >../list
455 grep "^ $rev1" list &&
456 grep "\\.\\./init" list
459 test_expect_success
'status should be "modified" after submodule commit' '
464 git commit -m "submodule commit 2"
467 rev2=$(cd init && git rev-parse HEAD) &&
469 git submodule status >list &&
474 test_expect_success
'the --cached sha1 should be rev1' '
475 git submodule --cached status >list &&
479 test_expect_success
'git diff should report the SHA1 of the new submodule commit' '
481 grep "^+Subproject commit $rev2" diff
484 test_expect_success
'update should checkout rev1' '
486 echo "$rev1" >expect &&
488 git submodule update init &&
491 test_cmp expect head-sha1
494 test_expect_success
'status should be "up-to-date" after update' '
495 git submodule status >list &&
499 test_expect_success
'checkout superproject with subproject already present' '
500 git checkout initial &&
504 test_expect_success
'apply submodule diff' '
512 git commit -m "change subproject"
514 git update-index --add init &&
515 git commit -m "change init" &&
516 git format-patch -1 --stdout >P.diff &&
517 git checkout second &&
518 git apply --index P.diff &&
520 git diff --cached master >staged &&
521 test_cmp empty staged
524 test_expect_success
'update --init' '
526 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
527 git config --remove-section submodule.example &&
528 test_must_fail git config submodule.example.url &&
530 git submodule update init 2> update.out &&
532 test_i18ngrep "not initialized" update.out &&
533 test_must_fail git rev-parse --resolve-git-dir init/.git &&
535 git submodule update --init init &&
536 git rev-parse --resolve-git-dir init/.git
539 test_expect_success
'update --init from subdirectory' '
541 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
542 git config --remove-section submodule.example &&
543 test_must_fail git config submodule.example.url &&
548 git submodule update ../init 2>update.out &&
550 test_i18ngrep "not initialized" update.out &&
551 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
553 git submodule update --init ../init
555 git rev-parse --resolve-git-dir init/.git
558 test_expect_success
'do not add files from a submodule' '
561 test_must_fail git add init/a
565 test_expect_success
'gracefully add/reset submodule with a trailing slash' '
568 git commit -m "commit subproject" init &&
572 git diff --exit-code --cached init &&
574 git commit -m update a >/dev/null &&
575 git rev-parse HEAD) &&
577 test_must_fail git diff --exit-code --cached init &&
578 test $commit = $(git ls-files --stage |
579 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
581 git diff --exit-code --cached init
585 test_expect_success
'ls-files gracefully handles trailing slash' '
587 test "init" = "$(git ls-files init/)"
591 test_expect_success
'moving to a commit without submodule does not leave empty dir' '
595 git checkout initial &&
600 test_expect_success
'submodule <invalid-subcommand> fails' '
601 test_must_fail git submodule no-such-subcommand
604 test_expect_success
'add submodules without specifying an explicit path' '
611 git commit -m "repo commit 1"
613 git clone --bare repo/ bare.git &&
616 git submodule add "$submodurl/repo" &&
617 git config -f .gitmodules submodule.repo.path repo &&
618 git submodule add "$submodurl/bare.git" &&
619 git config -f .gitmodules submodule.bare.path bare
623 test_expect_success
'add should fail when path is used by a file' '
627 test_must_fail git submodule add "$submodurl/repo" file
631 test_expect_success
'add should fail when path is used by an existing directory' '
635 test_must_fail git submodule add "$submodurl/repo" empty-dir
639 test_expect_success
'use superproject as upstream when path is relative and no url is set there' '
642 git submodule add ../repo relative &&
643 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
644 git submodule sync relative &&
645 test "$(git config submodule.relative.url)" = "$submodurl/repo"
649 test_expect_success
'set up for relative path tests' '
661 git config -f .gitmodules submodule.sub.path sub &&
662 git config -f .gitmodules submodule.sub.url ../subrepo &&
663 cp .git/config pristine-.git-config &&
664 cp .gitmodules pristine-.gitmodules
668 test_expect_success
'../subrepo works with URL - ssh://hostname/repo' '
671 cp pristine-.git-config .git/config &&
672 cp pristine-.gitmodules .gitmodules &&
673 git config remote.origin.url ssh://hostname/repo &&
674 git submodule init &&
675 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
679 test_expect_success
'../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
682 cp pristine-.git-config .git/config &&
683 cp pristine-.gitmodules .gitmodules &&
684 git config remote.origin.url ssh://hostname:22/repo &&
685 git submodule init &&
686 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
690 # About the choice of the path in the next test:
691 # - double-slash side-steps path mangling issues on Windows
692 # - it is still an absolute local path
693 # - there cannot be a server with a blank in its name just in case the
694 # path is used erroneously to access a //server/share style path
695 test_expect_success
'../subrepo path works with local path - //somewhere else/repo' '
698 cp pristine-.git-config .git/config &&
699 cp pristine-.gitmodules .gitmodules &&
700 git config remote.origin.url "//somewhere else/repo" &&
701 git submodule init &&
702 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
706 test_expect_success
'../subrepo works with file URL - file:///tmp/repo' '
709 cp pristine-.git-config .git/config &&
710 cp pristine-.gitmodules .gitmodules &&
711 git config remote.origin.url file:///tmp/repo &&
712 git submodule init &&
713 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
717 test_expect_success
'../subrepo works with helper URL- helper:://hostname/repo' '
720 cp pristine-.git-config .git/config &&
721 cp pristine-.gitmodules .gitmodules &&
722 git config remote.origin.url helper:://hostname/repo &&
723 git submodule init &&
724 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
728 test_expect_success
'../subrepo works with scp-style URL - user@host:repo' '
731 cp pristine-.git-config .git/config &&
732 git config remote.origin.url user@host:repo &&
733 git submodule init &&
734 test "$(git config submodule.sub.url)" = user@host:subrepo
738 test_expect_success
'../subrepo works with scp-style URL - user@host:path/to/repo' '
741 cp pristine-.git-config .git/config &&
742 cp pristine-.gitmodules .gitmodules &&
743 git config remote.origin.url user@host:path/to/repo &&
744 git submodule init &&
745 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
749 test_expect_success
'../subrepo works with relative local path - foo' '
752 cp pristine-.git-config .git/config &&
753 cp pristine-.gitmodules .gitmodules &&
754 git config remote.origin.url foo &&
755 # actual: fails with an error
756 git submodule init &&
757 test "$(git config submodule.sub.url)" = subrepo
761 test_expect_success
'../subrepo works with relative local path - foo/bar' '
764 cp pristine-.git-config .git/config &&
765 cp pristine-.gitmodules .gitmodules &&
766 git config remote.origin.url foo/bar &&
767 git submodule init &&
768 test "$(git config submodule.sub.url)" = foo/subrepo
772 test_expect_success
'../subrepo works with relative local path - ./foo' '
775 cp pristine-.git-config .git/config &&
776 cp pristine-.gitmodules .gitmodules &&
777 git config remote.origin.url ./foo &&
778 git submodule init &&
779 test "$(git config submodule.sub.url)" = subrepo
783 test_expect_success
'../subrepo works with relative local path - ./foo/bar' '
786 cp pristine-.git-config .git/config &&
787 cp pristine-.gitmodules .gitmodules &&
788 git config remote.origin.url ./foo/bar &&
789 git submodule init &&
790 test "$(git config submodule.sub.url)" = foo/subrepo
794 test_expect_success
'../subrepo works with relative local path - ../foo' '
797 cp pristine-.git-config .git/config &&
798 cp pristine-.gitmodules .gitmodules &&
799 git config remote.origin.url ../foo &&
800 git submodule init &&
801 test "$(git config submodule.sub.url)" = ../subrepo
805 test_expect_success
'../subrepo works with relative local path - ../foo/bar' '
808 cp pristine-.git-config .git/config &&
809 cp pristine-.gitmodules .gitmodules &&
810 git config remote.origin.url ../foo/bar &&
811 git submodule init &&
812 test "$(git config submodule.sub.url)" = ../foo/subrepo
816 test_expect_success
'../bar/a/b/c works with relative local path - ../foo/bar.git' '
819 cp pristine-.git-config .git/config &&
820 cp pristine-.gitmodules .gitmodules &&
822 (cd a/b/c && git init) &&
823 git config remote.origin.url ../foo/bar.git &&
824 git submodule add ../bar/a/b/c ./a/b/c &&
825 git submodule init &&
826 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
830 test_expect_success
'moving the superproject does not break submodules' '
833 git submodule status >expect
835 mv addtest addtest2 &&
838 git submodule status >actual &&
839 test_cmp expect actual
843 test_expect_success
'moving the submodule does not break the superproject' '
848 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
849 mv addtest2/repo addtest2/repo.bak &&
850 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
855 test_cmp expect actual
858 test_expect_success
'submodule add --name allows to replace a submodule with another at the same path' '
863 echo "$submodurl/repo" >expect &&
864 git config remote.origin.url >actual &&
865 test_cmp expect actual &&
866 echo "gitdir: ../.git/modules/repo" >expect &&
871 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
872 test_must_be_empty actual &&
873 echo "gitdir: ../.git/modules/submod" >expect &&
874 test_cmp expect submod/.git &&
877 echo "$submodurl/bare.git" >expect &&
878 git config remote.origin.url >actual &&
879 test_cmp expect actual &&
880 echo "gitdir: ../.git/modules/repo_new" >expect &&
883 echo "repo" >expect &&
884 test_must_fail git config -f .gitmodules submodule.repo.path &&
885 git config -f .gitmodules submodule.repo_new.path >actual &&
886 test_cmp expect actual&&
887 echo "$submodurl/repo" >expect &&
888 test_must_fail git config -f .gitmodules submodule.repo.url &&
889 echo "$submodurl/bare.git" >expect &&
890 git config -f .gitmodules submodule.repo_new.url >actual &&
891 test_cmp expect actual &&
892 echo "$submodurl/repo" >expect &&
893 git config submodule.repo.url >actual &&
894 test_cmp expect actual &&
895 echo "$submodurl/bare.git" >expect &&
896 git config submodule.repo_new.url >actual &&
897 test_cmp expect actual
901 test_expect_success
'recursive relative submodules stay relative' '
902 test_when_finished "rm -rf super clone2 subsub sub3" &&
909 git commit -m "initial commit"
917 git commit -m "initial commit" &&
918 git submodule add ../subsub dirdir/subsub &&
919 git commit -m "add submodule subsub"
927 git commit -m "initial commit" &&
928 git submodule add ../sub3 &&
929 git commit -m "add submodule sub"
931 git clone super clone2 &&
934 git submodule update --init --recursive &&
935 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
936 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
938 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
939 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
942 test_expect_success
'submodule add with an existing name fails unless forced' '
947 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
949 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
950 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
951 echo "$submodurl/bare.git" >expect &&
952 git config submodule.repo_new.url >actual &&
953 test_cmp expect actual &&
954 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
956 echo "repo" >expect &&
957 git config -f .gitmodules submodule.repo_new.path >actual &&
958 test_cmp expect actual&&
959 echo "$submodurl/repo.git" >expect &&
960 git config -f .gitmodules submodule.repo_new.url >actual &&
961 test_cmp expect actual &&
962 echo "$submodurl/repo.git" >expect &&
963 git config submodule.repo_new.url >actual &&
964 test_cmp expect actual
968 test_expect_success
'set up a second submodule' '
969 git submodule add ./init2 example2 &&
970 git commit -m "submodule example2 added"
973 test_expect_success
'submodule deinit works on repository without submodules' '
974 test_when_finished "rm -rf newdirectory" &&
975 mkdir newdirectory &&
981 git commit -m "repo should not be empty" &&
982 git submodule deinit . &&
983 git submodule deinit --all
987 test_expect_success
'submodule deinit should remove the whole submodule section from .git/config' '
988 git config submodule.example.foo bar &&
989 git config submodule.example2.frotz nitfol &&
990 git submodule deinit init &&
991 test -z "$(git config --get-regexp "submodule\.example\.")" &&
992 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
993 test -f example2/.git &&
997 test_expect_success
'submodule deinit should unset core.worktree' '
998 test_path_is_file .git/modules/example/config &&
999 test_must_fail git config -f .git/modules/example/config core.worktree
1002 test_expect_success
'submodule deinit from subdirectory' '
1003 git submodule update --init &&
1004 git config submodule.example.foo bar &&
1008 git submodule deinit ../init >../output
1010 test_i18ngrep "\\.\\./init" output &&
1011 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1012 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1013 test -f example2/.git &&
1017 test_expect_success
'submodule deinit . deinits all initialized submodules' '
1018 git submodule update --init &&
1019 git config submodule.example.foo bar &&
1020 git config submodule.example2.frotz nitfol &&
1021 test_must_fail git submodule deinit &&
1022 git submodule deinit . >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 --all deinits all initialized submodules' '
1031 git submodule update --init &&
1032 git config submodule.example.foo bar &&
1033 git config submodule.example2.frotz nitfol &&
1034 test_must_fail git submodule deinit &&
1035 git submodule deinit --all >actual &&
1036 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1037 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1038 test_i18ngrep "Cleared directory .init" actual &&
1039 test_i18ngrep "Cleared directory .example2" actual &&
1043 test_expect_success
'submodule deinit deinits a submodule when its work tree is missing or empty' '
1044 git submodule update --init &&
1045 rm -rf init example2/* example2/.git &&
1046 git submodule deinit init example2 >actual &&
1047 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1048 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1049 test_i18ngrep ! "Cleared directory .init" actual &&
1050 test_i18ngrep "Cleared directory .example2" actual &&
1054 test_expect_success
'submodule deinit fails when the submodule contains modifications unless forced' '
1055 git submodule update --init &&
1057 test_must_fail git submodule deinit init &&
1058 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1059 test -f example2/.git &&
1060 git submodule deinit -f init >actual &&
1061 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1062 test_i18ngrep "Cleared directory .init" actual &&
1066 test_expect_success
'submodule deinit fails when the submodule contains untracked files unless forced' '
1067 git submodule update --init &&
1068 echo X >>init/untracked &&
1069 test_must_fail git submodule deinit init &&
1070 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1071 test -f example2/.git &&
1072 git submodule deinit -f init >actual &&
1073 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1074 test_i18ngrep "Cleared directory .init" actual &&
1078 test_expect_success
'submodule deinit fails when the submodule HEAD does not match unless forced' '
1079 git submodule update --init &&
1084 test_must_fail git submodule deinit init &&
1085 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1086 test -f example2/.git &&
1087 git submodule deinit -f init >actual &&
1088 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1089 test_i18ngrep "Cleared directory .init" actual &&
1093 test_expect_success
'submodule deinit is silent when used on an uninitialized submodule' '
1094 git submodule update --init &&
1095 git submodule deinit init >actual &&
1096 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1097 test_i18ngrep "Cleared directory .init" actual &&
1098 git submodule deinit init >actual &&
1099 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1100 test_i18ngrep "Cleared directory .init" actual &&
1101 git submodule deinit . >actual &&
1102 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1103 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1104 test_i18ngrep "Cleared directory .init" actual &&
1105 git submodule deinit . >actual &&
1106 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1107 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1108 test_i18ngrep "Cleared directory .init" actual &&
1109 git submodule deinit --all >actual &&
1110 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1111 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1112 test_i18ngrep "Cleared directory .init" actual &&
1116 test_expect_success
'submodule deinit fails when submodule has a .git directory even when forced' '
1117 git submodule update --init &&
1121 cp -R ../.git/modules/example .git &&
1122 GIT_WORK_TREE=. git config --unset core.worktree
1124 test_must_fail git submodule deinit init &&
1125 test_must_fail git submodule deinit -f init &&
1126 test -d init/.git &&
1127 test -n "$(git config --get-regexp "submodule\.example\.")"
1130 test_expect_success
'submodule with UTF-8 name' '
1131 svname=$(printf "\303\245 \303\244\303\266") &&
1138 git commit -m "init sub"
1140 git submodule add ./"$svname" &&
1141 git submodule >&2 &&
1142 test -n "$(git submodule | grep "$svname")"
1145 test_expect_success
'submodule add clone shallow submodule' '
1151 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1154 test 1 = $(git log --oneline | wc -l)
1159 test_expect_success
'submodule helper list is not confused by common prefixes' '
1164 echo hi >testfile2 &&
1166 git commit -m "test1"
1172 echo hello >testfile1 &&
1174 git commit -m "test2"
1176 git submodule add /dir1/b dir1/b &&
1177 git submodule add /dir2/b dir2/b &&
1178 git commit -m "first submodule commit" &&
1179 git submodule--helper list dir1/b |cut -c51- >actual &&
1180 echo "dir1/b" >expect &&
1181 test_cmp expect actual
1184 test_expect_success
'setup superproject with submodules' '
1186 test_commit -C sub1 test &&
1187 test_commit -C sub1 test2 &&
1188 git init multisuper &&
1189 git -C multisuper submodule add ../sub1 sub0 &&
1190 git -C multisuper submodule add ../sub1 sub1 &&
1191 git -C multisuper submodule add ../sub1 sub2 &&
1192 git -C multisuper submodule add ../sub1 sub3 &&
1193 git -C multisuper commit -m "add some submodules"
1203 test_expect_success
'submodule update --init with a specification' '
1204 test_when_finished "rm -rf multisuper_clone" &&
1206 git clone file://"$pwd"/multisuper multisuper_clone &&
1207 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1208 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1209 test_cmp expect actual
1212 test_expect_success
'submodule update --init with submodule.active set' '
1213 test_when_finished "rm -rf multisuper_clone" &&
1215 git clone file://"$pwd"/multisuper multisuper_clone &&
1216 git -C multisuper_clone config submodule.active "." &&
1217 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1218 git -C multisuper_clone submodule update --init &&
1219 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1220 test_cmp expect actual
1223 test_expect_success
'submodule update and setting submodule.<name>.active' '
1224 test_when_finished "rm -rf multisuper_clone" &&
1226 git clone file://"$pwd"/multisuper multisuper_clone &&
1227 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1228 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1229 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1231 cat >expect <<-\EOF &&
1237 git -C multisuper_clone submodule update &&
1238 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1239 test_cmp expect actual
1242 test_expect_success
'clone --recurse-submodules with a pathspec works' '
1243 test_when_finished "rm -rf multisuper_clone" &&
1244 cat >expected <<-\EOF &&
1251 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1252 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1253 test_cmp expected actual
1256 test_expect_success
'clone with multiple --recurse-submodules options' '
1257 test_when_finished "rm -rf multisuper_clone" &&
1258 cat >expect <<-\EOF &&
1265 git clone --recurse-submodules="." \
1266 --recurse-submodules=":(exclude)sub0" \
1267 --recurse-submodules=":(exclude)sub2" \
1268 multisuper multisuper_clone &&
1269 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1270 test_cmp expect actual
1273 test_expect_success
'clone and subsequent updates correctly auto-initialize submodules' '
1274 test_when_finished "rm -rf multisuper_clone" &&
1275 cat <<-\EOF >expect &&
1282 cat <<-\EOF >expect2 &&
1291 git clone --recurse-submodules="." \
1292 --recurse-submodules=":(exclude)sub0" \
1293 --recurse-submodules=":(exclude)sub2" \
1294 --recurse-submodules=":(exclude)sub4" \
1295 multisuper multisuper_clone &&
1297 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1298 test_cmp expect actual &&
1300 git -C multisuper submodule add ../sub1 sub4 &&
1301 git -C multisuper submodule add ../sub1 sub5 &&
1302 git -C multisuper commit -m "add more submodules" &&
1303 # obtain the new superproject
1304 git -C multisuper_clone pull &&
1305 git -C multisuper_clone submodule update --init &&
1306 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1307 test_cmp expect2 actual
1310 test_expect_success
'init properly sets the config' '
1311 test_when_finished "rm -rf multisuper_clone" &&
1312 git clone --recurse-submodules="." \
1313 --recurse-submodules=":(exclude)sub0" \
1314 multisuper multisuper_clone &&
1316 git -C multisuper_clone submodule init -- sub0 sub1 &&
1317 git -C multisuper_clone config --get submodule.sub0.active &&
1318 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1321 test_expect_success
'recursive clone respects -q' '
1322 test_when_finished "rm -rf multisuper_clone" &&
1323 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1324 test_must_be_empty actual