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 &&
107 git submodule add -q "$submodurl" submod >actual &&
108 test_must_be_empty actual &&
109 echo "gitdir: ../.git/modules/submod" >expect &&
110 test_cmp expect submod/.git &&
113 git config core.worktree >actual &&
114 echo "../../../submod" >expect &&
115 test_cmp expect actual &&
121 rm -f heads head untracked &&
122 inspect addtest/submod ../.. &&
123 test_cmp expect heads &&
124 test_cmp expect head &&
125 test_must_be_empty untracked
128 test_expect_success 'setup parent and one repository' '
129 test_create_repo parent &&
130 test_commit -C parent one
133 test_expect_success 'redirected submodule add does not show progress' '
134 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
137 test_i18ngrep ! "Checking connectivity" err
140 test_expect_success 'redirected submodule add --progress does show progress' '
141 git -C addtest submodule add --progress "file://$submodurl/parent" \
142 submod-redirected-progress 2>err && \
146 test_expect_success 'submodule add to .gitignored path fails' '
149 cat <<-\EOF >expect &&
150 The following path is ignored by one of your .gitignore files:
152 Use -f if you really want to add it.
154 # Does not use test_commit due to the ignore
155 echo "*" > .gitignore &&
156 git add --force .gitignore &&
157 git commit -m"Ignore everything" &&
158 ! git submodule add "$submodurl" submod >actual 2>&1 &&
159 test_i18ncmp expect actual
163 test_expect_success 'submodule add to .gitignored path with --force' '
166 git submodule add --force "$submodurl" submod
170 test_expect_success 'submodule add to reconfigure existing submodule with --force' '
173 git submodule add --force bogus-url submod &&
174 git submodule add -b initial "$submodurl" submod-branch &&
175 test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
176 test "bogus-url" = "$(git config submodule.submod.url)" &&
178 git submodule add --force "$submodurl" submod
179 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
180 test "$submodurl" = "$(git config submodule.submod.url)"
184 test_expect_success 'submodule add --branch' '
185 echo "refs/heads/initial" >expect-head &&
186 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_must_be_empty untracked
205 test_expect_success 'submodule add with ./ in path' '
206 echo "refs/heads/master" >expect &&
210 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
214 rm -f heads head untracked &&
215 inspect addtest/dotsubmod/frotz ../../.. &&
216 test_cmp expect heads &&
217 test_cmp expect head &&
218 test_must_be_empty untracked
221 test_expect_success 'submodule add with /././ in path' '
222 echo "refs/heads/master" >expect &&
226 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
230 rm -f heads head untracked &&
231 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
232 test_cmp expect heads &&
233 test_cmp expect head &&
234 test_must_be_empty untracked
237 test_expect_success 'submodule add with // in path' '
238 echo "refs/heads/master" >expect &&
242 git submodule add "$submodurl" slashslashsubmod///frotz// &&
246 rm -f heads head untracked &&
247 inspect addtest/slashslashsubmod/frotz ../../.. &&
248 test_cmp expect heads &&
249 test_cmp expect head &&
250 test_must_be_empty untracked
253 test_expect_success 'submodule add with /.. in path' '
254 echo "refs/heads/master" >expect &&
258 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
262 rm -f heads head untracked &&
263 inspect addtest/realsubmod ../.. &&
264 test_cmp expect heads &&
265 test_cmp expect head &&
266 test_must_be_empty untracked
269 test_expect_success 'submodule add with ./, /.. and // in path' '
270 echo "refs/heads/master" >expect &&
274 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
278 rm -f heads head untracked &&
279 inspect addtest/realsubmod2 ../.. &&
280 test_cmp expect heads &&
281 test_cmp expect head &&
282 test_must_be_empty untracked
285 test_expect_success !CYGWIN 'submodule add with \\ in path' '
286 test_when_finished "rm -rf parent sub\\with\\backslash" &&
288 # Initialize a repo with a backslash in its name
289 git init sub\\with\\backslash &&
290 touch sub\\with\\backslash/empty.file &&
291 git -C sub\\with\\backslash add empty.file &&
292 git -C sub\\with\\backslash commit -m "Added empty.file" &&
294 # Add that repository as a submodule
296 git -C parent submodule add ../sub\\with\\backslash
299 test_expect_success 'submodule add in subdirectory' '
300 echo "refs/heads/master" >expect &&
305 git submodule add "$submodurl" ../realsubmod3 &&
309 rm -f heads head untracked &&
310 inspect addtest/realsubmod3 ../.. &&
311 test_cmp expect heads &&
312 test_cmp expect head &&
313 test_must_be_empty untracked
316 test_expect_success 'submodule add in subdirectory with relative path should fail' '
319 test_must_fail git submodule add ../../ submod3 2>../../output.err
321 test_i18ngrep toplevel output.err
324 test_expect_success 'setup - add an example entry to .gitmodules' '
325 git config --file=.gitmodules submodule.example.url git://example.com/init.git
328 test_expect_success 'status should fail for unmapped paths' '
329 test_must_fail git submodule status
332 test_expect_success 'setup - map path in .gitmodules' '
333 cat <<\EOF >expect &&
334 [submodule "example"]
335 url = git://example.com/init.git
339 git config --file=.gitmodules submodule.example.path init &&
341 test_cmp expect .gitmodules
344 test_expect_success 'status should only print one line' '
345 git submodule status >lines &&
346 test_line_count = 1 lines
349 test_expect_success 'setup - fetch commit name from submodule' '
350 rev1=$(cd .subrepo && git rev-parse HEAD) &&
351 printf "rev1: %s\n" "$rev1" &&
355 test_expect_success 'status should initially be "missing"' '
356 git submodule status >lines &&
360 test_expect_success 'init should register submodule url in .git/config' '
361 echo git://example.com/init.git >expect &&
363 git submodule init &&
364 git config submodule.example.url >url &&
365 git config submodule.example.url ./.subrepo &&
370 test_failure_with_unknown_submodule () {
371 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
372 grep "^error: .*no-such-submodule" output.err
375 test_expect_success 'init should fail with unknown submodule' '
376 test_failure_with_unknown_submodule init
379 test_expect_success 'update should fail with unknown submodule' '
380 test_failure_with_unknown_submodule update
383 test_expect_success 'status should fail with unknown submodule' '
384 test_failure_with_unknown_submodule status
387 test_expect_success 'sync should fail with unknown submodule' '
388 test_failure_with_unknown_submodule sync
391 test_expect_success 'update should fail when path is used by a file' '
392 echo hello >expect &&
394 echo "hello" >init &&
395 test_must_fail git submodule update &&
400 test_expect_success 'update should fail when path is used by a nonempty directory' '
401 echo hello >expect &&
405 echo "hello" >init/a &&
407 test_must_fail git submodule update &&
409 test_cmp expect init/a
412 test_expect_success 'update should work when path is an empty dir' '
415 echo "$rev1" >expect &&
418 git submodule update -q >update.out &&
419 test_must_be_empty update.out &&
422 test_cmp expect head-sha1
425 test_expect_success 'status should be "up-to-date" after update' '
426 git submodule status >list &&
430 test_expect_success 'status "up-to-date" from subdirectory' '
434 git submodule status >../list
436 grep "^ $rev1" list &&
437 grep "\\.\\./init" list
440 test_expect_success 'status "up-to-date" from subdirectory with path' '
444 git submodule status ../init >../list
446 grep "^ $rev1" list &&
447 grep "\\.\\./init" list
450 test_expect_success 'status should be "modified" after submodule commit' '
455 git commit -m "submodule commit 2"
458 rev2=$(cd init && git rev-parse HEAD) &&
460 git submodule status >list &&
465 test_expect_success 'the --cached sha1 should be rev1' '
466 git submodule --cached status >list &&
470 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
472 grep "^+Subproject commit $rev2" diff
475 test_expect_success 'update should checkout rev1' '
477 echo "$rev1" >expect &&
479 git submodule update init &&
482 test_cmp expect head-sha1
485 test_expect_success 'status should be "up-to-date" after update' '
486 git submodule status >list &&
490 test_expect_success 'checkout superproject with subproject already present' '
491 git checkout initial &&
495 test_expect_success 'apply submodule diff' '
501 git commit -m "change subproject"
503 git update-index --add init &&
504 git commit -m "change init" &&
505 git format-patch -1 --stdout >P.diff &&
506 git checkout second &&
507 git apply --index P.diff &&
509 git diff --cached master >staged &&
510 test_must_be_empty staged
513 test_expect_success 'update --init' '
515 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
516 git config --remove-section submodule.example &&
517 test_must_fail git config submodule.example.url &&
519 git submodule update init 2> update.out &&
521 test_i18ngrep "not initialized" update.out &&
522 test_must_fail git rev-parse --resolve-git-dir init/.git &&
524 git submodule update --init init &&
525 git rev-parse --resolve-git-dir init/.git
528 test_expect_success 'update --init from subdirectory' '
530 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
531 git config --remove-section submodule.example &&
532 test_must_fail git config submodule.example.url &&
537 git submodule update ../init 2>update.out &&
539 test_i18ngrep "not initialized" update.out &&
540 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
542 git submodule update --init ../init
544 git rev-parse --resolve-git-dir init/.git
547 test_expect_success 'do not add files from a submodule' '
550 test_must_fail git add init/a
554 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
557 git commit -m "commit subproject" init &&
561 git diff --exit-code --cached init &&
563 git commit -m update a >/dev/null &&
564 git rev-parse HEAD) &&
566 test_must_fail git diff --exit-code --cached init &&
567 test $commit = $(git ls-files --stage |
568 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
570 git diff --exit-code --cached init
574 test_expect_success 'ls-files gracefully handles trailing slash' '
576 test "init" = "$(git ls-files init/)"
580 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
584 git checkout initial &&
589 test_expect_success 'submodule <invalid-subcommand> fails' '
590 test_must_fail git submodule no-such-subcommand
593 test_expect_success 'add submodules without specifying an explicit path' '
600 git commit -m "repo commit 1"
602 git clone --bare repo/ bare.git &&
605 git submodule add "$submodurl/repo" &&
606 git config -f .gitmodules submodule.repo.path repo &&
607 git submodule add "$submodurl/bare.git" &&
608 git config -f .gitmodules submodule.bare.path bare
612 test_expect_success 'add should fail when path is used by a file' '
616 test_must_fail git submodule add "$submodurl/repo" file
620 test_expect_success 'add should fail when path is used by an existing directory' '
624 test_must_fail git submodule add "$submodurl/repo" empty-dir
628 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
631 git submodule add ../repo relative &&
632 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
633 git submodule sync relative &&
634 test "$(git config submodule.relative.url)" = "$submodurl/repo"
638 test_expect_success 'set up for relative path tests' '
650 git config -f .gitmodules submodule.sub.path sub &&
651 git config -f .gitmodules submodule.sub.url ../subrepo &&
652 cp .git/config pristine-.git-config &&
653 cp .gitmodules pristine-.gitmodules
657 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
660 cp pristine-.git-config .git/config &&
661 cp pristine-.gitmodules .gitmodules &&
662 git config remote.origin.url ssh://hostname/repo &&
663 git submodule init &&
664 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
668 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
671 cp pristine-.git-config .git/config &&
672 cp pristine-.gitmodules .gitmodules &&
673 git config remote.origin.url ssh://hostname:22/repo &&
674 git submodule init &&
675 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
679 # About the choice of the path in the next test:
680 # - double-slash side-steps path mangling issues on Windows
681 # - it is still an absolute local path
682 # - there cannot be a server with a blank in its name just in case the
683 # path is used erroneously to access a //server/share style path
684 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
687 cp pristine-.git-config .git/config &&
688 cp pristine-.gitmodules .gitmodules &&
689 git config remote.origin.url "//somewhere else/repo" &&
690 git submodule init &&
691 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
695 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
698 cp pristine-.git-config .git/config &&
699 cp pristine-.gitmodules .gitmodules &&
700 git config remote.origin.url file:///tmp/repo &&
701 git submodule init &&
702 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
706 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
709 cp pristine-.git-config .git/config &&
710 cp pristine-.gitmodules .gitmodules &&
711 git config remote.origin.url helper:://hostname/repo &&
712 git submodule init &&
713 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
717 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
720 cp pristine-.git-config .git/config &&
721 git config remote.origin.url user@host:repo &&
722 git submodule init &&
723 test "$(git config submodule.sub.url)" = user@host:subrepo
727 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
730 cp pristine-.git-config .git/config &&
731 cp pristine-.gitmodules .gitmodules &&
732 git config remote.origin.url user@host:path/to/repo &&
733 git submodule init &&
734 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
738 test_expect_success '../subrepo works with relative local path - foo' '
741 cp pristine-.git-config .git/config &&
742 cp pristine-.gitmodules .gitmodules &&
743 git config remote.origin.url foo &&
744 # actual: fails with an error
745 git submodule init &&
746 test "$(git config submodule.sub.url)" = subrepo
750 test_expect_success '../subrepo works with relative local path - foo/bar' '
753 cp pristine-.git-config .git/config &&
754 cp pristine-.gitmodules .gitmodules &&
755 git config remote.origin.url foo/bar &&
756 git submodule init &&
757 test "$(git config submodule.sub.url)" = foo/subrepo
761 test_expect_success '../subrepo works with relative local path - ./foo' '
764 cp pristine-.git-config .git/config &&
765 cp pristine-.gitmodules .gitmodules &&
766 git config remote.origin.url ./foo &&
767 git submodule init &&
768 test "$(git config submodule.sub.url)" = subrepo
772 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
775 cp pristine-.git-config .git/config &&
776 cp pristine-.gitmodules .gitmodules &&
777 git config remote.origin.url ./foo/bar &&
778 git submodule init &&
779 test "$(git config submodule.sub.url)" = foo/subrepo
783 test_expect_success '../subrepo works with relative local path - ../foo' '
786 cp pristine-.git-config .git/config &&
787 cp pristine-.gitmodules .gitmodules &&
788 git config remote.origin.url ../foo &&
789 git submodule init &&
790 test "$(git config submodule.sub.url)" = ../subrepo
794 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
797 cp pristine-.git-config .git/config &&
798 cp pristine-.gitmodules .gitmodules &&
799 git config remote.origin.url ../foo/bar &&
800 git submodule init &&
801 test "$(git config submodule.sub.url)" = ../foo/subrepo
805 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
808 cp pristine-.git-config .git/config &&
809 cp pristine-.gitmodules .gitmodules &&
811 (cd a/b/c; git init) &&
812 git config remote.origin.url ../foo/bar.git &&
813 git submodule add ../bar/a/b/c ./a/b/c &&
814 git submodule init &&
815 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
819 test_expect_success 'moving the superproject does not break submodules' '
822 git submodule status >expect
824 mv addtest addtest2 &&
827 git submodule status >actual &&
828 test_cmp expect actual
832 test_expect_success 'moving the submodule does not break the superproject' '
837 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
838 mv addtest2/repo addtest2/repo.bak &&
839 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
844 test_cmp expect actual
847 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
852 echo "$submodurl/repo" >expect &&
853 git config remote.origin.url >actual &&
854 test_cmp expect actual &&
855 echo "gitdir: ../.git/modules/repo" >expect &&
860 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
861 test_must_be_empty actual &&
862 echo "gitdir: ../.git/modules/submod" >expect &&
863 test_cmp expect submod/.git &&
866 echo "$submodurl/bare.git" >expect &&
867 git config remote.origin.url >actual &&
868 test_cmp expect actual &&
869 echo "gitdir: ../.git/modules/repo_new" >expect &&
872 echo "repo" >expect &&
873 test_must_fail git config -f .gitmodules submodule.repo.path &&
874 git config -f .gitmodules submodule.repo_new.path >actual &&
875 test_cmp expect actual&&
876 echo "$submodurl/repo" >expect &&
877 test_must_fail git config -f .gitmodules submodule.repo.url &&
878 echo "$submodurl/bare.git" >expect &&
879 git config -f .gitmodules submodule.repo_new.url >actual &&
880 test_cmp expect actual &&
881 echo "$submodurl/repo" >expect &&
882 git config submodule.repo.url >actual &&
883 test_cmp expect actual &&
884 echo "$submodurl/bare.git" >expect &&
885 git config submodule.repo_new.url >actual &&
886 test_cmp expect actual
890 test_expect_success 'recursive relative submodules stay relative' '
891 test_when_finished "rm -rf super clone2 subsub sub3" &&
898 git commit -m "initial commit"
906 git commit -m "initial commit" &&
907 git submodule add ../subsub dirdir/subsub &&
908 git commit -m "add submodule subsub"
916 git commit -m "initial commit" &&
917 git submodule add ../sub3 &&
918 git commit -m "add submodule sub"
920 git clone super clone2 &&
923 git submodule update --init --recursive &&
924 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
925 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
927 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
928 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
931 test_expect_success 'submodule add with an existing name fails unless forced' '
936 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
938 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
939 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
940 echo "$submodurl/bare.git" >expect &&
941 git config submodule.repo_new.url >actual &&
942 test_cmp expect actual &&
943 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
945 echo "repo" >expect &&
946 git config -f .gitmodules submodule.repo_new.path >actual &&
947 test_cmp expect actual&&
948 echo "$submodurl/repo.git" >expect &&
949 git config -f .gitmodules submodule.repo_new.url >actual &&
950 test_cmp expect actual &&
951 echo "$submodurl/repo.git" >expect &&
952 git config submodule.repo_new.url >actual &&
953 test_cmp expect actual
957 test_expect_success 'set up a second submodule' '
958 git submodule add ./init2 example2 &&
959 git commit -m "submodule example2 added"
962 test_expect_success 'submodule deinit works on repository without submodules' '
963 test_when_finished "rm -rf newdirectory" &&
964 mkdir newdirectory &&
970 git commit -m "repo should not be empty" &&
971 git submodule deinit . &&
972 git submodule deinit --all
976 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
977 git config submodule.example.foo bar &&
978 git config submodule.example2.frotz nitfol &&
979 git submodule deinit init &&
980 test -z "$(git config --get-regexp "submodule\.example\.")" &&
981 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
982 test -f example2/.git &&
986 test_expect_success 'submodule deinit should unset core.worktree' '
987 test_path_is_file .git/modules/example/config &&
988 test_must_fail git config -f .git/modules/example/config core.worktree
991 test_expect_success 'submodule deinit from subdirectory' '
992 git submodule update --init &&
993 git config submodule.example.foo bar &&
997 git submodule deinit ../init >../output
999 test_i18ngrep "\\.\\./init" output &&
1000 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1001 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1002 test -f example2/.git &&
1006 test_expect_success 'submodule deinit . deinits all initialized submodules' '
1007 git submodule update --init &&
1008 git config submodule.example.foo bar &&
1009 git config submodule.example2.frotz nitfol &&
1010 test_must_fail git submodule deinit &&
1011 git submodule deinit . >actual &&
1012 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1013 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1014 test_i18ngrep "Cleared directory .init" actual &&
1015 test_i18ngrep "Cleared directory .example2" actual &&
1019 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
1020 git submodule update --init &&
1021 git config submodule.example.foo bar &&
1022 git config submodule.example2.frotz nitfol &&
1023 test_must_fail git submodule deinit &&
1024 git submodule deinit --all >actual &&
1025 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1026 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1027 test_i18ngrep "Cleared directory .init" actual &&
1028 test_i18ngrep "Cleared directory .example2" actual &&
1032 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
1033 git submodule update --init &&
1034 rm -rf init example2/* example2/.git &&
1035 git submodule deinit init example2 >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 fails when the submodule contains modifications unless forced' '
1044 git submodule update --init &&
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 contains untracked files unless forced' '
1056 git submodule update --init &&
1057 echo X >>init/untracked &&
1058 test_must_fail git submodule deinit init &&
1059 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1060 test -f example2/.git &&
1061 git submodule deinit -f init >actual &&
1062 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1063 test_i18ngrep "Cleared directory .init" actual &&
1067 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1068 git submodule update --init &&
1073 test_must_fail git submodule deinit init &&
1074 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1075 test -f example2/.git &&
1076 git submodule deinit -f init >actual &&
1077 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1078 test_i18ngrep "Cleared directory .init" actual &&
1082 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1083 git submodule update --init &&
1084 git submodule deinit init >actual &&
1085 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1086 test_i18ngrep "Cleared directory .init" actual &&
1087 git submodule deinit init >actual &&
1088 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1089 test_i18ngrep "Cleared directory .init" actual &&
1090 git submodule deinit . >actual &&
1091 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1092 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1093 test_i18ngrep "Cleared directory .init" actual &&
1094 git submodule deinit . >actual &&
1095 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1096 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1097 test_i18ngrep "Cleared directory .init" actual &&
1098 git submodule deinit --all >actual &&
1099 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1100 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1101 test_i18ngrep "Cleared directory .init" actual &&
1105 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1106 git submodule update --init &&
1110 cp -R ../.git/modules/example .git &&
1111 GIT_WORK_TREE=. git config --unset core.worktree
1113 test_must_fail git submodule deinit init &&
1114 test_must_fail git submodule deinit -f init &&
1115 test -d init/.git &&
1116 test -n "$(git config --get-regexp "submodule\.example\.")"
1119 test_expect_success 'submodule with UTF-8 name' '
1120 svname=$(printf "\303\245 \303\244\303\266") &&
1127 git commit -m "init sub"
1129 git submodule add ./"$svname" &&
1130 git submodule >&2 &&
1131 test -n "$(git submodule | grep "$svname")"
1134 test_expect_success 'submodule add clone shallow submodule' '
1140 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1143 test 1 = $(git log --oneline | wc -l)
1148 test_expect_success 'submodule helper list is not confused by common prefixes' '
1153 echo hi >testfile2 &&
1155 git commit -m "test1"
1161 echo hello >testfile1 &&
1163 git commit -m "test2"
1165 git submodule add /dir1/b dir1/b &&
1166 git submodule add /dir2/b dir2/b &&
1167 git commit -m "first submodule commit" &&
1168 git submodule--helper list dir1/b |cut -c51- >actual &&
1169 echo "dir1/b" >expect &&
1170 test_cmp expect actual
1173 test_expect_success 'setup superproject with submodules' '
1175 test_commit -C sub1 test &&
1176 test_commit -C sub1 test2 &&
1177 git init multisuper &&
1178 git -C multisuper submodule add ../sub1 sub0 &&
1179 git -C multisuper submodule add ../sub1 sub1 &&
1180 git -C multisuper submodule add ../sub1 sub2 &&
1181 git -C multisuper submodule add ../sub1 sub3 &&
1182 git -C multisuper commit -m "add some submodules"
1192 test_expect_success 'submodule update --init with a specification' '
1193 test_when_finished "rm -rf multisuper_clone" &&
1195 git clone file://"$pwd"/multisuper multisuper_clone &&
1196 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1197 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1198 test_cmp expect actual
1201 test_expect_success 'submodule update --init with submodule.active set' '
1202 test_when_finished "rm -rf multisuper_clone" &&
1204 git clone file://"$pwd"/multisuper multisuper_clone &&
1205 git -C multisuper_clone config submodule.active "." &&
1206 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1207 git -C multisuper_clone submodule update --init &&
1208 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1209 test_cmp expect actual
1212 test_expect_success 'submodule update and setting submodule.<name>.active' '
1213 test_when_finished "rm -rf multisuper_clone" &&
1215 git clone file://"$pwd"/multisuper multisuper_clone &&
1216 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1217 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1218 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1220 cat >expect <<-\EOF &&
1226 git -C multisuper_clone submodule update &&
1227 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1228 test_cmp expect actual
1231 test_expect_success 'clone --recurse-submodules with a pathspec works' '
1232 test_when_finished "rm -rf multisuper_clone" &&
1233 cat >expected <<-\EOF &&
1240 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1241 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1242 test_cmp expected actual
1245 test_expect_success 'clone with multiple --recurse-submodules options' '
1246 test_when_finished "rm -rf multisuper_clone" &&
1247 cat >expect <<-\EOF &&
1254 git clone --recurse-submodules="." \
1255 --recurse-submodules=":(exclude)sub0" \
1256 --recurse-submodules=":(exclude)sub2" \
1257 multisuper multisuper_clone &&
1258 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1259 test_cmp expect actual
1262 test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
1263 test_when_finished "rm -rf multisuper_clone" &&
1264 cat <<-\EOF >expect &&
1271 cat <<-\EOF >expect2 &&
1280 git clone --recurse-submodules="." \
1281 --recurse-submodules=":(exclude)sub0" \
1282 --recurse-submodules=":(exclude)sub2" \
1283 --recurse-submodules=":(exclude)sub4" \
1284 multisuper multisuper_clone &&
1286 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1287 test_cmp expect actual &&
1289 git -C multisuper submodule add ../sub1 sub4 &&
1290 git -C multisuper submodule add ../sub1 sub5 &&
1291 git -C multisuper commit -m "add more submodules" &&
1292 # obtain the new superproject
1293 git -C multisuper_clone pull &&
1294 git -C multisuper_clone submodule update --init &&
1295 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1296 test_cmp expect2 actual
1299 test_expect_success 'init properly sets the config' '
1300 test_when_finished "rm -rf multisuper_clone" &&
1301 git clone --recurse-submodules="." \
1302 --recurse-submodules=":(exclude)sub0" \
1303 multisuper multisuper_clone &&
1305 git -C multisuper_clone submodule init -- sub0 sub1 &&
1306 git -C multisuper_clone config --get submodule.sub0.active &&
1307 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1310 test_expect_success 'recursive clone respects -q' '
1311 test_when_finished "rm -rf multisuper_clone" &&
1312 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1313 test_must_be_empty actual