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_create_repo parent &&
130 test_commit -C parent one
132 test_expect_success 'redirected submodule add does not show progress' '
133 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
136 test_i18ngrep ! "Checking connectivity" err
139 test_expect_success 'redirected submodule add --progress does show progress' '
140 git -C addtest submodule add --progress "file://$submodurl/parent" \
141 submod-redirected-progress 2>err && \
145 test_expect_success 'submodule add to .gitignored path fails' '
148 cat <<-\EOF >expect &&
149 The following path is ignored by one of your .gitignore files:
151 Use -f if you really want to add it.
153 # Does not use test_commit due to the ignore
154 echo "*" > .gitignore &&
155 git add --force .gitignore &&
156 git commit -m"Ignore everything" &&
157 ! git submodule add "$submodurl" submod >actual 2>&1 &&
158 test_i18ncmp expect actual
162 test_expect_success 'submodule add to .gitignored path with --force' '
165 git submodule add --force "$submodurl" submod
169 test_expect_success 'submodule add to reconfigure existing submodule with --force' '
172 git submodule add --force bogus-url submod &&
173 git submodule add -b initial "$submodurl" submod-branch &&
174 test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
175 test "bogus-url" = "$(git config submodule.submod.url)" &&
177 git submodule add --force "$submodurl" submod
178 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
179 test "$submodurl" = "$(git config submodule.submod.url)"
183 test_expect_success 'submodule add --branch' '
184 echo "refs/heads/initial" >expect-head &&
185 cat <<-\EOF >expect-heads &&
193 git submodule add -b initial "$submodurl" submod-branch &&
194 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
198 rm -f heads head untracked &&
199 inspect addtest/submod-branch ../.. &&
200 test_cmp expect-heads heads &&
201 test_cmp expect-head head &&
202 test_cmp empty untracked
205 test_expect_success 'submodule add with ./ in path' '
206 echo "refs/heads/master" >expect &&
211 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
215 rm -f heads head untracked &&
216 inspect addtest/dotsubmod/frotz ../../.. &&
217 test_cmp expect heads &&
218 test_cmp expect head &&
219 test_cmp empty untracked
222 test_expect_success 'submodule add with /././ in path' '
223 echo "refs/heads/master" >expect &&
228 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
232 rm -f heads head untracked &&
233 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
234 test_cmp expect heads &&
235 test_cmp expect head &&
236 test_cmp empty untracked
239 test_expect_success 'submodule add with // in path' '
240 echo "refs/heads/master" >expect &&
245 git submodule add "$submodurl" slashslashsubmod///frotz// &&
249 rm -f heads head untracked &&
250 inspect addtest/slashslashsubmod/frotz ../../.. &&
251 test_cmp expect heads &&
252 test_cmp expect head &&
253 test_cmp empty untracked
256 test_expect_success 'submodule add with /.. in path' '
257 echo "refs/heads/master" >expect &&
262 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
266 rm -f heads head untracked &&
267 inspect addtest/realsubmod ../.. &&
268 test_cmp expect heads &&
269 test_cmp expect head &&
270 test_cmp empty untracked
273 test_expect_success 'submodule add with ./, /.. and // in path' '
274 echo "refs/heads/master" >expect &&
279 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
283 rm -f heads head untracked &&
284 inspect addtest/realsubmod2 ../.. &&
285 test_cmp expect heads &&
286 test_cmp expect head &&
287 test_cmp empty untracked
290 test_expect_success !CYGWIN 'submodule add with \\ in path' '
291 test_when_finished "rm -rf parent sub\\with\\backslash" &&
293 # Initialize a repo with a backslash in its name
294 git init sub\\with\\backslash &&
295 touch sub\\with\\backslash/empty.file &&
296 git -C sub\\with\\backslash add empty.file &&
297 git -C sub\\with\\backslash commit -m "Added empty.file" &&
299 # Add that repository as a submodule
301 git -C parent submodule add ../sub\\with\\backslash
304 test_expect_success 'submodule add in subdirectory' '
305 echo "refs/heads/master" >expect &&
311 git submodule add "$submodurl" ../realsubmod3 &&
315 rm -f heads head untracked &&
316 inspect addtest/realsubmod3 ../.. &&
317 test_cmp expect heads &&
318 test_cmp expect head &&
319 test_cmp empty untracked
322 test_expect_success 'submodule add in subdirectory with relative path should fail' '
325 test_must_fail git submodule add ../../ submod3 2>../../output.err
327 test_i18ngrep toplevel output.err
330 test_expect_success 'setup - add an example entry to .gitmodules' '
331 git config --file=.gitmodules submodule.example.url git://example.com/init.git
334 test_expect_success 'status should fail for unmapped paths' '
335 test_must_fail git submodule status
338 test_expect_success 'setup - map path in .gitmodules' '
339 cat <<\EOF >expect &&
340 [submodule "example"]
341 url = git://example.com/init.git
345 git config --file=.gitmodules submodule.example.path init &&
347 test_cmp expect .gitmodules
350 test_expect_success 'status should only print one line' '
351 git submodule status >lines &&
352 test_line_count = 1 lines
355 test_expect_success 'setup - fetch commit name from submodule' '
356 rev1=$(cd .subrepo && git rev-parse HEAD) &&
357 printf "rev1: %s\n" "$rev1" &&
361 test_expect_success 'status should initially be "missing"' '
362 git submodule status >lines &&
366 test_expect_success 'init should register submodule url in .git/config' '
367 echo git://example.com/init.git >expect &&
369 git submodule init &&
370 git config submodule.example.url >url &&
371 git config submodule.example.url ./.subrepo &&
376 test_failure_with_unknown_submodule () {
377 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
378 grep "^error: .*no-such-submodule" output.err
381 test_expect_success 'init should fail with unknown submodule' '
382 test_failure_with_unknown_submodule init
385 test_expect_success 'update should fail with unknown submodule' '
386 test_failure_with_unknown_submodule update
389 test_expect_success 'status should fail with unknown submodule' '
390 test_failure_with_unknown_submodule status
393 test_expect_success 'sync should fail with unknown submodule' '
394 test_failure_with_unknown_submodule sync
397 test_expect_success 'update should fail when path is used by a file' '
398 echo hello >expect &&
400 echo "hello" >init &&
401 test_must_fail git submodule update &&
406 test_expect_success 'update should fail when path is used by a nonempty directory' '
407 echo hello >expect &&
411 echo "hello" >init/a &&
413 test_must_fail git submodule update &&
415 test_cmp expect init/a
418 test_expect_success 'update should work when path is an empty dir' '
421 echo "$rev1" >expect &&
424 git submodule update -q >update.out &&
425 test_must_be_empty update.out &&
428 test_cmp expect head-sha1
431 test_expect_success 'status should be "up-to-date" after update' '
432 git submodule status >list &&
436 test_expect_success 'status "up-to-date" from subdirectory' '
440 git submodule status >../list
442 grep "^ $rev1" list &&
443 grep "\\.\\./init" list
446 test_expect_success 'status "up-to-date" from subdirectory with path' '
450 git submodule status ../init >../list
452 grep "^ $rev1" list &&
453 grep "\\.\\./init" list
456 test_expect_success 'status should be "modified" after submodule commit' '
461 git commit -m "submodule commit 2"
464 rev2=$(cd init && git rev-parse HEAD) &&
466 git submodule status >list &&
471 test_expect_success 'the --cached sha1 should be rev1' '
472 git submodule --cached status >list &&
476 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
478 grep "^+Subproject commit $rev2" diff
481 test_expect_success 'update should checkout rev1' '
483 echo "$rev1" >expect &&
485 git submodule update init &&
488 test_cmp expect head-sha1
491 test_expect_success 'status should be "up-to-date" after update' '
492 git submodule status >list &&
496 test_expect_success 'checkout superproject with subproject already present' '
497 git checkout initial &&
501 test_expect_success 'apply submodule diff' '
509 git commit -m "change subproject"
511 git update-index --add init &&
512 git commit -m "change init" &&
513 git format-patch -1 --stdout >P.diff &&
514 git checkout second &&
515 git apply --index P.diff &&
517 git diff --cached master >staged &&
518 test_cmp empty staged
521 test_expect_success 'update --init' '
523 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
524 git config --remove-section submodule.example &&
525 test_must_fail git config submodule.example.url &&
527 git submodule update init 2> update.out &&
529 test_i18ngrep "not initialized" update.out &&
530 test_must_fail git rev-parse --resolve-git-dir init/.git &&
532 git submodule update --init init &&
533 git rev-parse --resolve-git-dir init/.git
536 test_expect_success 'update --init from subdirectory' '
538 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
539 git config --remove-section submodule.example &&
540 test_must_fail git config submodule.example.url &&
545 git submodule update ../init 2>update.out &&
547 test_i18ngrep "not initialized" update.out &&
548 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
550 git submodule update --init ../init
552 git rev-parse --resolve-git-dir init/.git
555 test_expect_success 'do not add files from a submodule' '
558 test_must_fail git add init/a
562 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
565 git commit -m "commit subproject" init &&
569 git diff --exit-code --cached init &&
571 git commit -m update a >/dev/null &&
572 git rev-parse HEAD) &&
574 test_must_fail git diff --exit-code --cached init &&
575 test $commit = $(git ls-files --stage |
576 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
578 git diff --exit-code --cached init
582 test_expect_success 'ls-files gracefully handles trailing slash' '
584 test "init" = "$(git ls-files init/)"
588 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
592 git checkout initial &&
597 test_expect_success 'submodule <invalid-subcommand> fails' '
598 test_must_fail git submodule no-such-subcommand
601 test_expect_success 'add submodules without specifying an explicit path' '
608 git commit -m "repo commit 1"
610 git clone --bare repo/ bare.git &&
613 git submodule add "$submodurl/repo" &&
614 git config -f .gitmodules submodule.repo.path repo &&
615 git submodule add "$submodurl/bare.git" &&
616 git config -f .gitmodules submodule.bare.path bare
620 test_expect_success 'add should fail when path is used by a file' '
624 test_must_fail git submodule add "$submodurl/repo" file
628 test_expect_success 'add should fail when path is used by an existing directory' '
632 test_must_fail git submodule add "$submodurl/repo" empty-dir
636 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
639 git submodule add ../repo relative &&
640 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
641 git submodule sync relative &&
642 test "$(git config submodule.relative.url)" = "$submodurl/repo"
646 test_expect_success 'set up for relative path tests' '
658 git config -f .gitmodules submodule.sub.path sub &&
659 git config -f .gitmodules submodule.sub.url ../subrepo &&
660 cp .git/config pristine-.git-config &&
661 cp .gitmodules pristine-.gitmodules
665 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
668 cp pristine-.git-config .git/config &&
669 cp pristine-.gitmodules .gitmodules &&
670 git config remote.origin.url ssh://hostname/repo &&
671 git submodule init &&
672 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
676 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
679 cp pristine-.git-config .git/config &&
680 cp pristine-.gitmodules .gitmodules &&
681 git config remote.origin.url ssh://hostname:22/repo &&
682 git submodule init &&
683 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
687 # About the choice of the path in the next test:
688 # - double-slash side-steps path mangling issues on Windows
689 # - it is still an absolute local path
690 # - there cannot be a server with a blank in its name just in case the
691 # path is used erroneously to access a //server/share style path
692 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
695 cp pristine-.git-config .git/config &&
696 cp pristine-.gitmodules .gitmodules &&
697 git config remote.origin.url "//somewhere else/repo" &&
698 git submodule init &&
699 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
703 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
706 cp pristine-.git-config .git/config &&
707 cp pristine-.gitmodules .gitmodules &&
708 git config remote.origin.url file:///tmp/repo &&
709 git submodule init &&
710 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
714 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
717 cp pristine-.git-config .git/config &&
718 cp pristine-.gitmodules .gitmodules &&
719 git config remote.origin.url helper:://hostname/repo &&
720 git submodule init &&
721 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
725 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
728 cp pristine-.git-config .git/config &&
729 git config remote.origin.url user@host:repo &&
730 git submodule init &&
731 test "$(git config submodule.sub.url)" = user@host:subrepo
735 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
738 cp pristine-.git-config .git/config &&
739 cp pristine-.gitmodules .gitmodules &&
740 git config remote.origin.url user@host:path/to/repo &&
741 git submodule init &&
742 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
746 test_expect_success '../subrepo works with relative local path - foo' '
749 cp pristine-.git-config .git/config &&
750 cp pristine-.gitmodules .gitmodules &&
751 git config remote.origin.url foo &&
752 # actual: fails with an error
753 git submodule init &&
754 test "$(git config submodule.sub.url)" = subrepo
758 test_expect_success '../subrepo works with relative local path - foo/bar' '
761 cp pristine-.git-config .git/config &&
762 cp pristine-.gitmodules .gitmodules &&
763 git config remote.origin.url foo/bar &&
764 git submodule init &&
765 test "$(git config submodule.sub.url)" = foo/subrepo
769 test_expect_success '../subrepo works with relative local path - ./foo' '
772 cp pristine-.git-config .git/config &&
773 cp pristine-.gitmodules .gitmodules &&
774 git config remote.origin.url ./foo &&
775 git submodule init &&
776 test "$(git config submodule.sub.url)" = subrepo
780 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
783 cp pristine-.git-config .git/config &&
784 cp pristine-.gitmodules .gitmodules &&
785 git config remote.origin.url ./foo/bar &&
786 git submodule init &&
787 test "$(git config submodule.sub.url)" = foo/subrepo
791 test_expect_success '../subrepo works with relative local path - ../foo' '
794 cp pristine-.git-config .git/config &&
795 cp pristine-.gitmodules .gitmodules &&
796 git config remote.origin.url ../foo &&
797 git submodule init &&
798 test "$(git config submodule.sub.url)" = ../subrepo
802 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
805 cp pristine-.git-config .git/config &&
806 cp pristine-.gitmodules .gitmodules &&
807 git config remote.origin.url ../foo/bar &&
808 git submodule init &&
809 test "$(git config submodule.sub.url)" = ../foo/subrepo
813 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
816 cp pristine-.git-config .git/config &&
817 cp pristine-.gitmodules .gitmodules &&
819 (cd a/b/c; git init) &&
820 git config remote.origin.url ../foo/bar.git &&
821 git submodule add ../bar/a/b/c ./a/b/c &&
822 git submodule init &&
823 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
827 test_expect_success 'moving the superproject does not break submodules' '
830 git submodule status >expect
832 mv addtest addtest2 &&
835 git submodule status >actual &&
836 test_cmp expect actual
840 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
845 echo "$submodurl/repo" >expect &&
846 git config remote.origin.url >actual &&
847 test_cmp expect actual &&
848 echo "gitdir: ../.git/modules/repo" >expect &&
853 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
854 test_must_be_empty actual &&
855 echo "gitdir: ../.git/modules/submod" >expect &&
856 test_cmp expect submod/.git &&
859 echo "$submodurl/bare.git" >expect &&
860 git config remote.origin.url >actual &&
861 test_cmp expect actual &&
862 echo "gitdir: ../.git/modules/repo_new" >expect &&
865 echo "repo" >expect &&
866 test_must_fail git config -f .gitmodules submodule.repo.path &&
867 git config -f .gitmodules submodule.repo_new.path >actual &&
868 test_cmp expect actual&&
869 echo "$submodurl/repo" >expect &&
870 test_must_fail git config -f .gitmodules submodule.repo.url &&
871 echo "$submodurl/bare.git" >expect &&
872 git config -f .gitmodules submodule.repo_new.url >actual &&
873 test_cmp expect actual &&
874 echo "$submodurl/repo" >expect &&
875 git config submodule.repo.url >actual &&
876 test_cmp expect actual &&
877 echo "$submodurl/bare.git" >expect &&
878 git config submodule.repo_new.url >actual &&
879 test_cmp expect actual
883 test_expect_success 'recursive relative submodules stay relative' '
884 test_when_finished "rm -rf super clone2 subsub sub3" &&
891 git commit -m "initial commit"
899 git commit -m "initial commit" &&
900 git submodule add ../subsub dirdir/subsub &&
901 git commit -m "add submodule subsub"
909 git commit -m "initial commit" &&
910 git submodule add ../sub3 &&
911 git commit -m "add submodule sub"
913 git clone super clone2 &&
916 git submodule update --init --recursive &&
917 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
918 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
920 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
921 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
924 test_expect_success 'submodule add with an existing name fails unless forced' '
929 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
931 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
932 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
933 echo "$submodurl/bare.git" >expect &&
934 git config submodule.repo_new.url >actual &&
935 test_cmp expect actual &&
936 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
938 echo "repo" >expect &&
939 git config -f .gitmodules submodule.repo_new.path >actual &&
940 test_cmp expect actual&&
941 echo "$submodurl/repo.git" >expect &&
942 git config -f .gitmodules submodule.repo_new.url >actual &&
943 test_cmp expect actual &&
944 echo "$submodurl/repo.git" >expect &&
945 git config submodule.repo_new.url >actual &&
946 test_cmp expect actual
950 test_expect_success 'set up a second submodule' '
951 git submodule add ./init2 example2 &&
952 git commit -m "submodule example2 added"
955 test_expect_success 'submodule deinit works on repository without submodules' '
956 test_when_finished "rm -rf newdirectory" &&
957 mkdir newdirectory &&
963 git commit -m "repo should not be empty" &&
964 git submodule deinit . &&
965 git submodule deinit --all
969 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
970 git config submodule.example.foo bar &&
971 git config submodule.example2.frotz nitfol &&
972 git submodule deinit init &&
973 test -z "$(git config --get-regexp "submodule\.example\.")" &&
974 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
975 test -f example2/.git &&
979 test_expect_success 'submodule deinit from subdirectory' '
980 git submodule update --init &&
981 git config submodule.example.foo bar &&
985 git submodule deinit ../init >../output
987 test_i18ngrep "\\.\\./init" output &&
988 test -z "$(git config --get-regexp "submodule\.example\.")" &&
989 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
990 test -f example2/.git &&
994 test_expect_success 'submodule deinit . deinits all initialized submodules' '
995 git submodule update --init &&
996 git config submodule.example.foo bar &&
997 git config submodule.example2.frotz nitfol &&
998 test_must_fail git submodule deinit &&
999 git submodule deinit . >actual &&
1000 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1001 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1002 test_i18ngrep "Cleared directory .init" actual &&
1003 test_i18ngrep "Cleared directory .example2" actual &&
1007 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
1008 git submodule update --init &&
1009 git config submodule.example.foo bar &&
1010 git config submodule.example2.frotz nitfol &&
1011 test_must_fail git submodule deinit &&
1012 git submodule deinit --all >actual &&
1013 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1014 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1015 test_i18ngrep "Cleared directory .init" actual &&
1016 test_i18ngrep "Cleared directory .example2" actual &&
1020 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
1021 git submodule update --init &&
1022 rm -rf init example2/* example2/.git &&
1023 git submodule deinit init example2 >actual &&
1024 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1025 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1026 test_i18ngrep ! "Cleared directory .init" actual &&
1027 test_i18ngrep "Cleared directory .example2" actual &&
1031 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
1032 git submodule update --init &&
1034 test_must_fail git submodule deinit init &&
1035 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1036 test -f example2/.git &&
1037 git submodule deinit -f init >actual &&
1038 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1039 test_i18ngrep "Cleared directory .init" actual &&
1043 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
1044 git submodule update --init &&
1045 echo X >>init/untracked &&
1046 test_must_fail git submodule deinit init &&
1047 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1048 test -f example2/.git &&
1049 git submodule deinit -f init >actual &&
1050 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1051 test_i18ngrep "Cleared directory .init" actual &&
1055 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1056 git submodule update --init &&
1061 test_must_fail git submodule deinit init &&
1062 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1063 test -f example2/.git &&
1064 git submodule deinit -f init >actual &&
1065 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1066 test_i18ngrep "Cleared directory .init" actual &&
1070 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1071 git submodule update --init &&
1072 git submodule deinit init >actual &&
1073 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1074 test_i18ngrep "Cleared directory .init" actual &&
1075 git submodule deinit init >actual &&
1076 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1077 test_i18ngrep "Cleared directory .init" actual &&
1078 git submodule deinit . >actual &&
1079 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1080 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1081 test_i18ngrep "Cleared directory .init" actual &&
1082 git submodule deinit . >actual &&
1083 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1084 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1085 test_i18ngrep "Cleared directory .init" actual &&
1086 git submodule deinit --all >actual &&
1087 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1088 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1089 test_i18ngrep "Cleared directory .init" actual &&
1093 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1094 git submodule update --init &&
1098 cp -R ../.git/modules/example .git &&
1099 GIT_WORK_TREE=. git config --unset core.worktree
1101 test_must_fail git submodule deinit init &&
1102 test_must_fail git submodule deinit -f init &&
1103 test -d init/.git &&
1104 test -n "$(git config --get-regexp "submodule\.example\.")"
1107 test_expect_success 'submodule with UTF-8 name' '
1108 svname=$(printf "\303\245 \303\244\303\266") &&
1115 git commit -m "init sub"
1117 git submodule add ./"$svname" &&
1118 git submodule >&2 &&
1119 test -n "$(git submodule | grep "$svname")"
1122 test_expect_success 'submodule add clone shallow submodule' '
1128 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1131 test 1 = $(git log --oneline | wc -l)
1136 test_expect_success 'submodule helper list is not confused by common prefixes' '
1141 echo hi >testfile2 &&
1143 git commit -m "test1"
1149 echo hello >testfile1 &&
1151 git commit -m "test2"
1153 git submodule add /dir1/b dir1/b &&
1154 git submodule add /dir2/b dir2/b &&
1155 git commit -m "first submodule commit" &&
1156 git submodule--helper list dir1/b |cut -c51- >actual &&
1157 echo "dir1/b" >expect &&
1158 test_cmp expect actual
1161 test_expect_success 'setup superproject with submodules' '
1163 test_commit -C sub1 test &&
1164 test_commit -C sub1 test2 &&
1165 git init multisuper &&
1166 git -C multisuper submodule add ../sub1 sub0 &&
1167 git -C multisuper submodule add ../sub1 sub1 &&
1168 git -C multisuper submodule add ../sub1 sub2 &&
1169 git -C multisuper submodule add ../sub1 sub3 &&
1170 git -C multisuper commit -m "add some submodules"
1180 test_expect_success 'submodule update --init with a specification' '
1181 test_when_finished "rm -rf multisuper_clone" &&
1183 git clone file://"$pwd"/multisuper multisuper_clone &&
1184 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1185 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1186 test_cmp expect actual
1189 test_expect_success 'submodule update --init with submodule.active set' '
1190 test_when_finished "rm -rf multisuper_clone" &&
1192 git clone file://"$pwd"/multisuper multisuper_clone &&
1193 git -C multisuper_clone config submodule.active "." &&
1194 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1195 git -C multisuper_clone submodule update --init &&
1196 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1197 test_cmp expect actual
1200 test_expect_success 'submodule update and setting submodule.<name>.active' '
1201 test_when_finished "rm -rf multisuper_clone" &&
1203 git clone file://"$pwd"/multisuper multisuper_clone &&
1204 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1205 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1206 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1208 cat >expect <<-\EOF &&
1214 git -C multisuper_clone submodule update &&
1215 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1216 test_cmp expect actual
1219 test_expect_success 'clone --recurse-submodules with a pathspec works' '
1220 test_when_finished "rm -rf multisuper_clone" &&
1221 cat >expected <<-\EOF &&
1228 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1229 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1230 test_cmp expected actual
1233 test_expect_success 'clone with multiple --recurse-submodules options' '
1234 test_when_finished "rm -rf multisuper_clone" &&
1235 cat >expect <<-\EOF &&
1242 git clone --recurse-submodules="." \
1243 --recurse-submodules=":(exclude)sub0" \
1244 --recurse-submodules=":(exclude)sub2" \
1245 multisuper multisuper_clone &&
1246 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1247 test_cmp expect actual
1250 test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
1251 test_when_finished "rm -rf multisuper_clone" &&
1252 cat <<-\EOF >expect &&
1259 cat <<-\EOF >expect2 &&
1268 git clone --recurse-submodules="." \
1269 --recurse-submodules=":(exclude)sub0" \
1270 --recurse-submodules=":(exclude)sub2" \
1271 --recurse-submodules=":(exclude)sub4" \
1272 multisuper multisuper_clone &&
1274 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1275 test_cmp expect actual &&
1277 git -C multisuper submodule add ../sub1 sub4 &&
1278 git -C multisuper submodule add ../sub1 sub5 &&
1279 git -C multisuper commit -m "add more submodules" &&
1280 # obtain the new superproject
1281 git -C multisuper_clone pull &&
1282 git -C multisuper_clone submodule update --init &&
1283 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1284 test_cmp expect2 actual
1287 test_expect_success 'init properly sets the config' '
1288 test_when_finished "rm -rf multisuper_clone" &&
1289 git clone --recurse-submodules="." \
1290 --recurse-submodules=":(exclude)sub0" \
1291 multisuper multisuper_clone &&
1293 git -C multisuper_clone submodule init -- sub0 sub1 &&
1294 git -C multisuper_clone config --get submodule.sub0.active &&
1295 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1298 test_expect_success 'recursive clone respects -q' '
1299 test_when_finished "rm -rf multisuper_clone" &&
1300 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1301 test_must_be_empty actual