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 'add aborts on repository with no commits' '
50 cat >expect <<-\EOF &&
51 '"'repo-no-commits'"' does not have a commit checked out
53 git init repo-no-commits &&
54 test_must_fail git submodule add ../a ./repo-no-commits 2>actual &&
55 test_i18ncmp expect actual
58 test_expect_success 'setup - repository in init subdirectory' '
65 git commit -m "submodule commit 1" &&
66 git tag -a -m "rev-1" rev-1
70 test_expect_success 'setup - commit with gitlink' '
74 git commit -m "super commit 1"
77 test_expect_success 'setup - hide init subdirectory' '
81 test_expect_success 'setup - repository to add submodules to' '
83 git init addtest-ignore
86 # The 'submodule add' tests need some repository to add as a submodule.
87 # The trash directory is a good one as any. We need to canonicalize
88 # the name, though, as some tests compare it to the absolute path git
89 # generates, which will expand symbolic links.
93 git for-each-ref --format='%(refname)' 'refs/heads/*'
102 listbranches >"$dotdot/heads" &&
103 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
104 git rev-parse HEAD >"$dotdot/head-sha1" &&
105 git update-index --refresh &&
106 git diff-files --exit-code &&
107 git clean -n -d -x >"$dotdot/untracked"
111 test_expect_success 'submodule add' '
112 echo "refs/heads/master" >expect &&
116 git submodule add -q "$submodurl" submod >actual &&
117 test_must_be_empty actual &&
118 echo "gitdir: ../.git/modules/submod" >expect &&
119 test_cmp expect submod/.git &&
122 git config core.worktree >actual &&
123 echo "../../../submod" >expect &&
124 test_cmp expect actual &&
130 rm -f heads head untracked &&
131 inspect addtest/submod ../.. &&
132 test_cmp expect heads &&
133 test_cmp expect head &&
134 test_must_be_empty untracked
137 test_expect_success 'setup parent and one repository' '
138 test_create_repo parent &&
139 test_commit -C parent one
142 test_expect_success 'redirected submodule add does not show progress' '
143 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
146 test_i18ngrep ! "Checking connectivity" err
149 test_expect_success 'redirected submodule add --progress does show progress' '
150 git -C addtest submodule add --progress "file://$submodurl/parent" \
151 submod-redirected-progress 2>err && \
155 test_expect_success 'submodule add to .gitignored path fails' '
158 cat <<-\EOF >expect &&
159 The following path is ignored by one of your .gitignore files:
161 Use -f if you really want to add it.
163 # Does not use test_commit due to the ignore
164 echo "*" > .gitignore &&
165 git add --force .gitignore &&
166 git commit -m"Ignore everything" &&
167 ! git submodule add "$submodurl" submod >actual 2>&1 &&
168 test_i18ncmp expect actual
172 test_expect_success 'submodule add to .gitignored path with --force' '
175 git submodule add --force "$submodurl" submod
179 test_expect_success 'submodule add to reconfigure existing submodule with --force' '
182 bogus_url="$(pwd)/bogus-url" &&
183 git submodule add --force "$bogus_url" submod &&
184 git submodule add --force -b initial "$submodurl" submod-branch &&
185 test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" &&
186 test "$bogus_url" = "$(git config submodule.submod.url)" &&
188 git submodule add --force "$submodurl" submod &&
189 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
190 test "$submodurl" = "$(git config submodule.submod.url)"
194 test_expect_success 'submodule add --branch' '
195 echo "refs/heads/initial" >expect-head &&
196 cat <<-\EOF >expect-heads &&
203 git submodule add -b initial "$submodurl" submod-branch &&
204 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
208 rm -f heads head untracked &&
209 inspect addtest/submod-branch ../.. &&
210 test_cmp expect-heads heads &&
211 test_cmp expect-head head &&
212 test_must_be_empty untracked
215 test_expect_success 'submodule add with ./ in path' '
216 echo "refs/heads/master" >expect &&
220 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
224 rm -f heads head untracked &&
225 inspect addtest/dotsubmod/frotz ../../.. &&
226 test_cmp expect heads &&
227 test_cmp expect head &&
228 test_must_be_empty untracked
231 test_expect_success 'submodule add with /././ in path' '
232 echo "refs/heads/master" >expect &&
236 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
240 rm -f heads head untracked &&
241 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
242 test_cmp expect heads &&
243 test_cmp expect head &&
244 test_must_be_empty untracked
247 test_expect_success 'submodule add with // in path' '
248 echo "refs/heads/master" >expect &&
252 git submodule add "$submodurl" slashslashsubmod///frotz// &&
256 rm -f heads head untracked &&
257 inspect addtest/slashslashsubmod/frotz ../../.. &&
258 test_cmp expect heads &&
259 test_cmp expect head &&
260 test_must_be_empty untracked
263 test_expect_success 'submodule add with /.. in path' '
264 echo "refs/heads/master" >expect &&
268 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
272 rm -f heads head untracked &&
273 inspect addtest/realsubmod ../.. &&
274 test_cmp expect heads &&
275 test_cmp expect head &&
276 test_must_be_empty untracked
279 test_expect_success 'submodule add with ./, /.. and // in path' '
280 echo "refs/heads/master" >expect &&
284 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
288 rm -f heads head untracked &&
289 inspect addtest/realsubmod2 ../.. &&
290 test_cmp expect heads &&
291 test_cmp expect head &&
292 test_must_be_empty untracked
295 test_expect_success !CYGWIN 'submodule add with \\ in path' '
296 test_when_finished "rm -rf parent sub\\with\\backslash" &&
298 # Initialize a repo with a backslash in its name
299 git init sub\\with\\backslash &&
300 touch sub\\with\\backslash/empty.file &&
301 git -C sub\\with\\backslash add empty.file &&
302 git -C sub\\with\\backslash commit -m "Added empty.file" &&
304 # Add that repository as a submodule
306 git -C parent submodule add ../sub\\with\\backslash
309 test_expect_success 'submodule add in subdirectory' '
310 echo "refs/heads/master" >expect &&
315 git submodule add "$submodurl" ../realsubmod3 &&
319 rm -f heads head untracked &&
320 inspect addtest/realsubmod3 ../.. &&
321 test_cmp expect heads &&
322 test_cmp expect head &&
323 test_must_be_empty untracked
326 test_expect_success 'submodule add in subdirectory with relative path should fail' '
329 test_must_fail git submodule add ../../ submod3 2>../../output.err
331 test_i18ngrep toplevel output.err
334 test_expect_success 'setup - add an example entry to .gitmodules' '
335 git config --file=.gitmodules submodule.example.url git://example.com/init.git
338 test_expect_success 'status should fail for unmapped paths' '
339 test_must_fail git submodule status
342 test_expect_success 'setup - map path in .gitmodules' '
343 cat <<\EOF >expect &&
344 [submodule "example"]
345 url = git://example.com/init.git
349 git config --file=.gitmodules submodule.example.path init &&
351 test_cmp expect .gitmodules
354 test_expect_success 'status should only print one line' '
355 git submodule status >lines &&
356 test_line_count = 1 lines
359 test_expect_success 'setup - fetch commit name from submodule' '
360 rev1=$(cd .subrepo && git rev-parse HEAD) &&
361 printf "rev1: %s\n" "$rev1" &&
365 test_expect_success 'status should initially be "missing"' '
366 git submodule status >lines &&
370 test_expect_success 'init should register submodule url in .git/config' '
371 echo git://example.com/init.git >expect &&
373 git submodule init &&
374 git config submodule.example.url >url &&
375 git config submodule.example.url ./.subrepo &&
380 test_expect_failure 'status should still be "missing" after initializing' '
383 git submodule status >lines &&
388 test_failure_with_unknown_submodule () {
389 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
390 test_i18ngrep "^error: .*no-such-submodule" output.err
393 test_expect_success 'init should fail with unknown submodule' '
394 test_failure_with_unknown_submodule init
397 test_expect_success 'update should fail with unknown submodule' '
398 test_failure_with_unknown_submodule update
401 test_expect_success 'status should fail with unknown submodule' '
402 test_failure_with_unknown_submodule status
405 test_expect_success 'sync should fail with unknown submodule' '
406 test_failure_with_unknown_submodule sync
409 test_expect_success 'update should fail when path is used by a file' '
410 echo hello >expect &&
412 echo "hello" >init &&
413 test_must_fail git submodule update &&
418 test_expect_success 'update should fail when path is used by a nonempty directory' '
419 echo hello >expect &&
423 echo "hello" >init/a &&
425 test_must_fail git submodule update &&
427 test_cmp expect init/a
430 test_expect_success 'update should work when path is an empty dir' '
433 echo "$rev1" >expect &&
436 git submodule update -q >update.out &&
437 test_must_be_empty update.out &&
440 test_cmp expect head-sha1
443 test_expect_success 'status should be "up-to-date" after update' '
444 git submodule status >list &&
448 test_expect_success 'status "up-to-date" from subdirectory' '
452 git submodule status >../list
454 grep "^ $rev1" list &&
455 grep "\\.\\./init" list
458 test_expect_success 'status "up-to-date" from subdirectory with path' '
462 git submodule status ../init >../list
464 grep "^ $rev1" list &&
465 grep "\\.\\./init" list
468 test_expect_success 'status should be "modified" after submodule commit' '
473 git commit -m "submodule commit 2"
476 rev2=$(cd init && git rev-parse HEAD) &&
478 git submodule status >list &&
483 test_expect_success 'the --cached sha1 should be rev1' '
484 git submodule --cached status >list &&
488 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
490 grep "^+Subproject commit $rev2" diff
493 test_expect_success 'update should checkout rev1' '
495 echo "$rev1" >expect &&
497 git submodule update init &&
500 test_cmp expect head-sha1
503 test_expect_success 'status should be "up-to-date" after update' '
504 git submodule status >list &&
508 test_expect_success 'checkout superproject with subproject already present' '
509 git checkout initial &&
513 test_expect_success 'apply submodule diff' '
519 git commit -m "change subproject"
521 git update-index --add init &&
522 git commit -m "change init" &&
523 git format-patch -1 --stdout >P.diff &&
524 git checkout second &&
525 git apply --index P.diff &&
527 git diff --cached master >staged &&
528 test_must_be_empty staged
531 test_expect_success 'update --init' '
533 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
534 git config --remove-section submodule.example &&
535 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 &&
543 git rev-parse --resolve-git-dir init/.git
546 test_expect_success 'update --init from subdirectory' '
548 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
549 git config --remove-section submodule.example &&
550 test_must_fail git config submodule.example.url &&
555 git submodule update ../init 2>update.out &&
557 test_i18ngrep "not initialized" update.out &&
558 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
560 git submodule update --init ../init
562 git rev-parse --resolve-git-dir init/.git
565 test_expect_success 'do not add files from a submodule' '
568 test_must_fail git add init/a
572 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
575 git commit -m "commit subproject" init &&
579 git diff --exit-code --cached init &&
581 git commit -m update a >/dev/null &&
582 git rev-parse HEAD) &&
584 test_must_fail git diff --exit-code --cached init &&
585 test $commit = $(git ls-files --stage |
586 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
588 git diff --exit-code --cached init
592 test_expect_success 'ls-files gracefully handles trailing slash' '
594 test "init" = "$(git ls-files init/)"
598 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
602 git checkout initial &&
607 test_expect_success 'submodule <invalid-subcommand> fails' '
608 test_must_fail git submodule no-such-subcommand
611 test_expect_success 'add submodules without specifying an explicit path' '
618 git commit -m "repo commit 1"
620 git clone --bare repo/ bare.git &&
623 git submodule add "$submodurl/repo" &&
624 git config -f .gitmodules submodule.repo.path repo &&
625 git submodule add "$submodurl/bare.git" &&
626 git config -f .gitmodules submodule.bare.path bare
630 test_expect_success 'add should fail when path is used by a file' '
634 test_must_fail git submodule add "$submodurl/repo" file
638 test_expect_success 'add should fail when path is used by an existing directory' '
642 test_must_fail git submodule add "$submodurl/repo" empty-dir
646 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
649 git submodule add ../repo relative &&
650 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
651 git submodule sync relative &&
652 test "$(git config submodule.relative.url)" = "$submodurl/repo"
656 test_expect_success 'set up for relative path tests' '
668 git config -f .gitmodules submodule.sub.path sub &&
669 git config -f .gitmodules submodule.sub.url ../subrepo &&
670 cp .git/config pristine-.git-config &&
671 cp .gitmodules pristine-.gitmodules
675 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
678 cp pristine-.git-config .git/config &&
679 cp pristine-.gitmodules .gitmodules &&
680 git config remote.origin.url ssh://hostname/repo &&
681 git submodule init &&
682 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
686 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
689 cp pristine-.git-config .git/config &&
690 cp pristine-.gitmodules .gitmodules &&
691 git config remote.origin.url ssh://hostname:22/repo &&
692 git submodule init &&
693 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
697 # About the choice of the path in the next test:
698 # - double-slash side-steps path mangling issues on Windows
699 # - it is still an absolute local path
700 # - there cannot be a server with a blank in its name just in case the
701 # path is used erroneously to access a //server/share style path
702 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
705 cp pristine-.git-config .git/config &&
706 cp pristine-.gitmodules .gitmodules &&
707 git config remote.origin.url "//somewhere else/repo" &&
708 git submodule init &&
709 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
713 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
716 cp pristine-.git-config .git/config &&
717 cp pristine-.gitmodules .gitmodules &&
718 git config remote.origin.url file:///tmp/repo &&
719 git submodule init &&
720 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
724 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
727 cp pristine-.git-config .git/config &&
728 cp pristine-.gitmodules .gitmodules &&
729 git config remote.origin.url helper:://hostname/repo &&
730 git submodule init &&
731 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
735 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
738 cp pristine-.git-config .git/config &&
739 git config remote.origin.url user@host:repo &&
740 git submodule init &&
741 test "$(git config submodule.sub.url)" = user@host:subrepo
745 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
748 cp pristine-.git-config .git/config &&
749 cp pristine-.gitmodules .gitmodules &&
750 git config remote.origin.url user@host:path/to/repo &&
751 git submodule init &&
752 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
756 test_expect_success '../subrepo works with relative local path - foo' '
759 cp pristine-.git-config .git/config &&
760 cp pristine-.gitmodules .gitmodules &&
761 git config remote.origin.url foo &&
762 # actual: fails with an error
763 git submodule init &&
764 test "$(git config submodule.sub.url)" = subrepo
768 test_expect_success '../subrepo works with relative local path - foo/bar' '
771 cp pristine-.git-config .git/config &&
772 cp pristine-.gitmodules .gitmodules &&
773 git config remote.origin.url foo/bar &&
774 git submodule init &&
775 test "$(git config submodule.sub.url)" = foo/subrepo
779 test_expect_success '../subrepo works with relative local path - ./foo' '
782 cp pristine-.git-config .git/config &&
783 cp pristine-.gitmodules .gitmodules &&
784 git config remote.origin.url ./foo &&
785 git submodule init &&
786 test "$(git config submodule.sub.url)" = subrepo
790 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
793 cp pristine-.git-config .git/config &&
794 cp pristine-.gitmodules .gitmodules &&
795 git config remote.origin.url ./foo/bar &&
796 git submodule init &&
797 test "$(git config submodule.sub.url)" = foo/subrepo
801 test_expect_success '../subrepo works with relative local path - ../foo' '
804 cp pristine-.git-config .git/config &&
805 cp pristine-.gitmodules .gitmodules &&
806 git config remote.origin.url ../foo &&
807 git submodule init &&
808 test "$(git config submodule.sub.url)" = ../subrepo
812 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
815 cp pristine-.git-config .git/config &&
816 cp pristine-.gitmodules .gitmodules &&
817 git config remote.origin.url ../foo/bar &&
818 git submodule init &&
819 test "$(git config submodule.sub.url)" = ../foo/subrepo
823 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
826 cp pristine-.git-config .git/config &&
827 cp pristine-.gitmodules .gitmodules &&
829 (cd a/b/c && git init && test_commit msg) &&
830 git config remote.origin.url ../foo/bar.git &&
831 git submodule add ../bar/a/b/c ./a/b/c &&
832 git submodule init &&
833 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
837 test_expect_success 'moving the superproject does not break submodules' '
840 git submodule status >expect
842 mv addtest addtest2 &&
845 git submodule status >actual &&
846 test_cmp expect actual
850 test_expect_success 'moving the submodule does not break the superproject' '
855 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
856 mv addtest2/repo addtest2/repo.bak &&
857 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
862 test_cmp expect actual
865 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
870 echo "$submodurl/repo" >expect &&
871 git config remote.origin.url >actual &&
872 test_cmp expect actual &&
873 echo "gitdir: ../.git/modules/repo" >expect &&
878 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
879 test_must_be_empty actual &&
880 echo "gitdir: ../.git/modules/submod" >expect &&
881 test_cmp expect submod/.git &&
884 echo "$submodurl/bare.git" >expect &&
885 git config remote.origin.url >actual &&
886 test_cmp expect actual &&
887 echo "gitdir: ../.git/modules/repo_new" >expect &&
890 echo "repo" >expect &&
891 test_must_fail git config -f .gitmodules submodule.repo.path &&
892 git config -f .gitmodules submodule.repo_new.path >actual &&
893 test_cmp expect actual&&
894 echo "$submodurl/repo" >expect &&
895 test_must_fail git config -f .gitmodules submodule.repo.url &&
896 echo "$submodurl/bare.git" >expect &&
897 git config -f .gitmodules submodule.repo_new.url >actual &&
898 test_cmp expect actual &&
899 echo "$submodurl/repo" >expect &&
900 git config submodule.repo.url >actual &&
901 test_cmp expect actual &&
902 echo "$submodurl/bare.git" >expect &&
903 git config submodule.repo_new.url >actual &&
904 test_cmp expect actual
908 test_expect_success 'recursive relative submodules stay relative' '
909 test_when_finished "rm -rf super clone2 subsub sub3" &&
916 git commit -m "initial commit"
924 git commit -m "initial commit" &&
925 git submodule add ../subsub dirdir/subsub &&
926 git commit -m "add submodule subsub"
934 git commit -m "initial commit" &&
935 git submodule add ../sub3 &&
936 git commit -m "add submodule sub"
938 git clone super clone2 &&
941 git submodule update --init --recursive &&
942 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
943 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
945 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
946 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
949 test_expect_success 'submodule add with an existing name fails unless forced' '
954 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
956 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
957 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
958 echo "$submodurl/bare.git" >expect &&
959 git config submodule.repo_new.url >actual &&
960 test_cmp expect actual &&
961 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
963 echo "repo" >expect &&
964 git config -f .gitmodules submodule.repo_new.path >actual &&
965 test_cmp expect actual&&
966 echo "$submodurl/repo.git" >expect &&
967 git config -f .gitmodules submodule.repo_new.url >actual &&
968 test_cmp expect actual &&
969 echo "$submodurl/repo.git" >expect &&
970 git config submodule.repo_new.url >actual &&
971 test_cmp expect actual
975 test_expect_success 'set up a second submodule' '
976 git submodule add ./init2 example2 &&
977 git commit -m "submodule example2 added"
980 test_expect_success 'submodule deinit works on repository without submodules' '
981 test_when_finished "rm -rf newdirectory" &&
982 mkdir newdirectory &&
988 git commit -m "repo should not be empty" &&
989 git submodule deinit . &&
990 git submodule deinit --all
994 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
995 git config submodule.example.foo bar &&
996 git config submodule.example2.frotz nitfol &&
997 git submodule deinit init &&
998 test -z "$(git config --get-regexp "submodule\.example\.")" &&
999 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1000 test -f example2/.git &&
1004 test_expect_success 'submodule deinit should unset core.worktree' '
1005 test_path_is_file .git/modules/example/config &&
1006 test_must_fail git config -f .git/modules/example/config core.worktree
1009 test_expect_success 'submodule deinit from subdirectory' '
1010 git submodule update --init &&
1011 git config submodule.example.foo bar &&
1015 git submodule deinit ../init >../output
1017 test_i18ngrep "\\.\\./init" output &&
1018 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1019 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1020 test -f example2/.git &&
1024 test_expect_success 'submodule deinit . deinits all initialized submodules' '
1025 git submodule update --init &&
1026 git config submodule.example.foo bar &&
1027 git config submodule.example2.frotz nitfol &&
1028 test_must_fail git submodule deinit &&
1029 git submodule deinit . >actual &&
1030 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1031 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1032 test_i18ngrep "Cleared directory .init" actual &&
1033 test_i18ngrep "Cleared directory .example2" actual &&
1037 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
1038 git submodule update --init &&
1039 git config submodule.example.foo bar &&
1040 git config submodule.example2.frotz nitfol &&
1041 test_must_fail git submodule deinit &&
1042 git submodule deinit --all >actual &&
1043 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1044 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1045 test_i18ngrep "Cleared directory .init" actual &&
1046 test_i18ngrep "Cleared directory .example2" actual &&
1050 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
1051 git submodule update --init &&
1052 rm -rf init example2/* example2/.git &&
1053 git submodule deinit init example2 >actual &&
1054 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1055 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1056 test_i18ngrep ! "Cleared directory .init" actual &&
1057 test_i18ngrep "Cleared directory .example2" actual &&
1061 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
1062 git submodule update --init &&
1064 test_must_fail git submodule deinit init &&
1065 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1066 test -f example2/.git &&
1067 git submodule deinit -f init >actual &&
1068 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1069 test_i18ngrep "Cleared directory .init" actual &&
1073 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
1074 git submodule update --init &&
1075 echo X >>init/untracked &&
1076 test_must_fail git submodule deinit init &&
1077 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1078 test -f example2/.git &&
1079 git submodule deinit -f init >actual &&
1080 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1081 test_i18ngrep "Cleared directory .init" actual &&
1085 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1086 git submodule update --init &&
1091 test_must_fail git submodule deinit init &&
1092 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1093 test -f example2/.git &&
1094 git submodule deinit -f init >actual &&
1095 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1096 test_i18ngrep "Cleared directory .init" actual &&
1100 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1101 git submodule update --init &&
1102 git submodule deinit init >actual &&
1103 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1104 test_i18ngrep "Cleared directory .init" actual &&
1105 git submodule deinit init >actual &&
1106 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1107 test_i18ngrep "Cleared directory .init" actual &&
1108 git submodule deinit . >actual &&
1109 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1110 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1111 test_i18ngrep "Cleared directory .init" actual &&
1112 git submodule deinit . >actual &&
1113 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1114 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1115 test_i18ngrep "Cleared directory .init" actual &&
1116 git submodule deinit --all >actual &&
1117 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1118 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1119 test_i18ngrep "Cleared directory .init" actual &&
1123 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1124 git submodule update --init &&
1128 cp -R ../.git/modules/example .git &&
1129 GIT_WORK_TREE=. git config --unset core.worktree
1131 test_must_fail git submodule deinit init &&
1132 test_must_fail git submodule deinit -f init &&
1133 test -d init/.git &&
1134 test -n "$(git config --get-regexp "submodule\.example\.")"
1137 test_expect_success 'submodule with UTF-8 name' '
1138 svname=$(printf "\303\245 \303\244\303\266") &&
1145 git commit -m "init sub"
1147 git submodule add ./"$svname" &&
1148 git submodule >&2 &&
1149 test -n "$(git submodule | grep "$svname")"
1152 test_expect_success 'submodule add clone shallow submodule' '
1158 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1161 test 1 = $(git log --oneline | wc -l)
1166 test_expect_success 'submodule helper list is not confused by common prefixes' '
1171 echo hi >testfile2 &&
1173 git commit -m "test1"
1179 echo hello >testfile1 &&
1181 git commit -m "test2"
1183 git submodule add /dir1/b dir1/b &&
1184 git submodule add /dir2/b dir2/b &&
1185 git commit -m "first submodule commit" &&
1186 git submodule--helper list dir1/b |cut -c51- >actual &&
1187 echo "dir1/b" >expect &&
1188 test_cmp expect actual
1191 test_expect_success 'setup superproject with submodules' '
1193 test_commit -C sub1 test &&
1194 test_commit -C sub1 test2 &&
1195 git init multisuper &&
1196 git -C multisuper submodule add ../sub1 sub0 &&
1197 git -C multisuper submodule add ../sub1 sub1 &&
1198 git -C multisuper submodule add ../sub1 sub2 &&
1199 git -C multisuper submodule add ../sub1 sub3 &&
1200 git -C multisuper commit -m "add some submodules"
1210 test_expect_success 'submodule update --init with a specification' '
1211 test_when_finished "rm -rf multisuper_clone" &&
1213 git clone file://"$pwd"/multisuper multisuper_clone &&
1214 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1215 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1216 test_cmp expect actual
1219 test_expect_success 'submodule update --init with submodule.active set' '
1220 test_when_finished "rm -rf multisuper_clone" &&
1222 git clone file://"$pwd"/multisuper multisuper_clone &&
1223 git -C multisuper_clone config submodule.active "." &&
1224 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1225 git -C multisuper_clone submodule update --init &&
1226 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1227 test_cmp expect actual
1230 test_expect_success 'submodule update and setting submodule.<name>.active' '
1231 test_when_finished "rm -rf multisuper_clone" &&
1233 git clone file://"$pwd"/multisuper multisuper_clone &&
1234 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1235 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1236 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1238 cat >expect <<-\EOF &&
1244 git -C multisuper_clone submodule update &&
1245 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1246 test_cmp expect actual
1249 test_expect_success 'clone active submodule without submodule url set' '
1250 test_when_finished "rm -rf test/test" &&
1252 # another dir breaks accidental relative paths still being correct
1253 git clone file://"$pwd"/multisuper test/test &&
1256 git config submodule.active "." &&
1258 # do not pass --init flag, as the submodule is already active:
1259 git submodule update &&
1260 git submodule status >actual_raw &&
1262 cut -c 1,43- actual_raw >actual &&
1263 cat >expect <<-\EOF &&
1269 test_cmp expect actual
1273 test_expect_success 'clone --recurse-submodules with a pathspec works' '
1274 test_when_finished "rm -rf multisuper_clone" &&
1275 cat >expected <<-\EOF &&
1282 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1283 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1284 test_cmp expected actual
1287 test_expect_success 'clone with multiple --recurse-submodules options' '
1288 test_when_finished "rm -rf multisuper_clone" &&
1289 cat >expect <<-\EOF &&
1296 git clone --recurse-submodules="." \
1297 --recurse-submodules=":(exclude)sub0" \
1298 --recurse-submodules=":(exclude)sub2" \
1299 multisuper multisuper_clone &&
1300 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1301 test_cmp expect actual
1304 test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
1305 test_when_finished "rm -rf multisuper_clone" &&
1306 cat <<-\EOF >expect &&
1313 cat <<-\EOF >expect2 &&
1322 git clone --recurse-submodules="." \
1323 --recurse-submodules=":(exclude)sub0" \
1324 --recurse-submodules=":(exclude)sub2" \
1325 --recurse-submodules=":(exclude)sub4" \
1326 multisuper multisuper_clone &&
1328 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1329 test_cmp expect actual &&
1331 git -C multisuper submodule add ../sub1 sub4 &&
1332 git -C multisuper submodule add ../sub1 sub5 &&
1333 git -C multisuper commit -m "add more submodules" &&
1334 # obtain the new superproject
1335 git -C multisuper_clone pull &&
1336 git -C multisuper_clone submodule update --init &&
1337 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1338 test_cmp expect2 actual
1341 test_expect_success 'init properly sets the config' '
1342 test_when_finished "rm -rf multisuper_clone" &&
1343 git clone --recurse-submodules="." \
1344 --recurse-submodules=":(exclude)sub0" \
1345 multisuper multisuper_clone &&
1347 git -C multisuper_clone submodule init -- sub0 sub1 &&
1348 git -C multisuper_clone config --get submodule.sub0.active &&
1349 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1352 test_expect_success 'recursive clone respects -q' '
1353 test_when_finished "rm -rf multisuper_clone" &&
1354 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1355 test_must_be_empty actual