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 'setup - initial commit' '
17 git commit -m "initial commit" &&
21 test_expect_success 'submodule init aborts on missing .gitmodules file' '
22 test_when_finished "git update-index --remove sub" &&
23 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
24 # missing the .gitmodules file here
25 test_must_fail git submodule init 2>actual &&
26 test_i18ngrep "No url found for submodule path" actual
29 test_expect_success 'submodule update aborts on missing .gitmodules file' '
30 test_when_finished "git update-index --remove sub" &&
31 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
32 # missing the .gitmodules file here
33 git submodule update sub 2>actual &&
34 test_i18ngrep "Submodule path .sub. not initialized" actual
37 test_expect_success 'configuration parsing' '
38 test_when_finished "rm -f .gitmodules" &&
39 cat >.gitmodules <<-\EOF &&
44 test_must_fail git status
47 test_expect_success 'setup - repository in init subdirectory' '
54 git commit -m "submodule commit 1" &&
55 git tag -a -m "rev-1" rev-1
59 test_expect_success 'setup - commit with gitlink' '
63 git commit -m "super commit 1"
66 test_expect_success 'setup - hide init subdirectory' '
70 test_expect_success 'setup - repository to add submodules to' '
72 git init addtest-ignore
75 # The 'submodule add' tests need some repository to add as a submodule.
76 # The trash directory is a good one as any. We need to canonicalize
77 # the name, though, as some tests compare it to the absolute path git
78 # generates, which will expand symbolic links.
82 git for-each-ref --format='%(refname)' 'refs/heads/*'
91 listbranches >"$dotdot/heads" &&
92 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
93 git rev-parse HEAD >"$dotdot/head-sha1" &&
94 git update-index --refresh &&
95 git diff-files --exit-code &&
96 git clean -n -d -x >"$dotdot/untracked"
100 test_expect_success 'submodule add' '
101 echo "refs/heads/master" >expect &&
106 git submodule add -q "$submodurl" submod >actual &&
107 test_must_be_empty actual &&
108 echo "gitdir: ../.git/modules/submod" >expect &&
109 test_cmp expect submod/.git &&
112 git config core.worktree >actual &&
113 echo "../../../submod" >expect &&
114 test_cmp expect actual &&
120 rm -f heads head untracked &&
121 inspect addtest/submod ../.. &&
122 test_cmp expect heads &&
123 test_cmp expect head &&
124 test_cmp empty untracked
127 test_expect_success 'submodule add to .gitignored path fails' '
130 cat <<-\EOF >expect &&
131 The following path is ignored by one of your .gitignore files:
133 Use -f if you really want to add it.
135 # Does not use test_commit due to the ignore
136 echo "*" > .gitignore &&
137 git add --force .gitignore &&
138 git commit -m"Ignore everything" &&
139 ! git submodule add "$submodurl" submod >actual 2>&1 &&
140 test_i18ncmp expect actual
144 test_expect_success 'submodule add to .gitignored path with --force' '
147 git submodule add --force "$submodurl" submod
151 test_expect_success 'submodule add --branch' '
152 echo "refs/heads/initial" >expect-head &&
153 cat <<-\EOF >expect-heads &&
161 git submodule add -b initial "$submodurl" submod-branch &&
162 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
166 rm -f heads head untracked &&
167 inspect addtest/submod-branch ../.. &&
168 test_cmp expect-heads heads &&
169 test_cmp expect-head head &&
170 test_cmp empty untracked
173 test_expect_success 'submodule add with ./ in path' '
174 echo "refs/heads/master" >expect &&
179 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
183 rm -f heads head untracked &&
184 inspect addtest/dotsubmod/frotz ../../.. &&
185 test_cmp expect heads &&
186 test_cmp expect head &&
187 test_cmp empty untracked
190 test_expect_success 'submodule add with /././ in path' '
191 echo "refs/heads/master" >expect &&
196 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
200 rm -f heads head untracked &&
201 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
202 test_cmp expect heads &&
203 test_cmp expect head &&
204 test_cmp empty untracked
207 test_expect_success 'submodule add with // in path' '
208 echo "refs/heads/master" >expect &&
213 git submodule add "$submodurl" slashslashsubmod///frotz// &&
217 rm -f heads head untracked &&
218 inspect addtest/slashslashsubmod/frotz ../../.. &&
219 test_cmp expect heads &&
220 test_cmp expect head &&
221 test_cmp empty untracked
224 test_expect_success 'submodule add with /.. in path' '
225 echo "refs/heads/master" >expect &&
230 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
234 rm -f heads head untracked &&
235 inspect addtest/realsubmod ../.. &&
236 test_cmp expect heads &&
237 test_cmp expect head &&
238 test_cmp empty untracked
241 test_expect_success 'submodule add with ./, /.. and // in path' '
242 echo "refs/heads/master" >expect &&
247 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
251 rm -f heads head untracked &&
252 inspect addtest/realsubmod2 ../.. &&
253 test_cmp expect heads &&
254 test_cmp expect head &&
255 test_cmp empty untracked
258 test_expect_success 'submodule add in subdirectory' '
259 echo "refs/heads/master" >expect &&
265 git submodule add "$submodurl" ../realsubmod3 &&
269 rm -f heads head untracked &&
270 inspect addtest/realsubmod3 ../.. &&
271 test_cmp expect heads &&
272 test_cmp expect head &&
273 test_cmp empty untracked
276 test_expect_success 'submodule add in subdirectory with relative path should fail' '
279 test_must_fail git submodule add ../../ submod3 2>../../output.err
281 test_i18ngrep toplevel output.err
284 test_expect_success 'setup - add an example entry to .gitmodules' '
285 git config --file=.gitmodules submodule.example.url git://example.com/init.git
288 test_expect_success 'status should fail for unmapped paths' '
289 test_must_fail git submodule status
292 test_expect_success 'setup - map path in .gitmodules' '
293 cat <<\EOF >expect &&
294 [submodule "example"]
295 url = git://example.com/init.git
299 git config --file=.gitmodules submodule.example.path init &&
301 test_cmp expect .gitmodules
304 test_expect_success 'status should only print one line' '
305 git submodule status >lines &&
306 test_line_count = 1 lines
309 test_expect_success 'setup - fetch commit name from submodule' '
310 rev1=$(cd .subrepo && git rev-parse HEAD) &&
311 printf "rev1: %s\n" "$rev1" &&
315 test_expect_success 'status should initially be "missing"' '
316 git submodule status >lines &&
320 test_expect_success 'init should register submodule url in .git/config' '
321 echo git://example.com/init.git >expect &&
323 git submodule init &&
324 git config submodule.example.url >url &&
325 git config submodule.example.url ./.subrepo &&
330 test_failure_with_unknown_submodule () {
331 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
332 grep "^error: .*no-such-submodule" output.err
335 test_expect_success 'init should fail with unknown submodule' '
336 test_failure_with_unknown_submodule init
339 test_expect_success 'update should fail with unknown submodule' '
340 test_failure_with_unknown_submodule update
343 test_expect_success 'status should fail with unknown submodule' '
344 test_failure_with_unknown_submodule status
347 test_expect_success 'sync should fail with unknown submodule' '
348 test_failure_with_unknown_submodule sync
351 test_expect_success 'update should fail when path is used by a file' '
352 echo hello >expect &&
354 echo "hello" >init &&
355 test_must_fail git submodule update &&
360 test_expect_success 'update should fail when path is used by a nonempty directory' '
361 echo hello >expect &&
365 echo "hello" >init/a &&
367 test_must_fail git submodule update &&
369 test_cmp expect init/a
372 test_expect_success 'update should work when path is an empty dir' '
375 echo "$rev1" >expect &&
378 git submodule update -q >update.out &&
379 test_must_be_empty update.out &&
382 test_cmp expect head-sha1
385 test_expect_success 'status should be "up-to-date" after update' '
386 git submodule status >list &&
390 test_expect_success 'status "up-to-date" from subdirectory' '
394 git submodule status >../list
396 grep "^ $rev1" list &&
397 grep "\\.\\./init" list
400 test_expect_success 'status "up-to-date" from subdirectory with path' '
404 git submodule status ../init >../list
406 grep "^ $rev1" list &&
407 grep "\\.\\./init" list
410 test_expect_success 'status should be "modified" after submodule commit' '
415 git commit -m "submodule commit 2"
418 rev2=$(cd init && git rev-parse HEAD) &&
420 git submodule status >list &&
425 test_expect_success 'the --cached sha1 should be rev1' '
426 git submodule --cached status >list &&
430 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
432 grep "^+Subproject commit $rev2" diff
435 test_expect_success 'update should checkout rev1' '
437 echo "$rev1" >expect &&
439 git submodule update init &&
442 test_cmp expect head-sha1
445 test_expect_success 'status should be "up-to-date" after update' '
446 git submodule status >list &&
450 test_expect_success 'checkout superproject with subproject already present' '
451 git checkout initial &&
455 test_expect_success 'apply submodule diff' '
463 git commit -m "change subproject"
465 git update-index --add init &&
466 git commit -m "change init" &&
467 git format-patch -1 --stdout >P.diff &&
468 git checkout second &&
469 git apply --index P.diff &&
471 git diff --cached master >staged &&
472 test_cmp empty staged
475 test_expect_success 'update --init' '
477 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
478 git config --remove-section submodule.example &&
479 test_must_fail git config submodule.example.url &&
481 git submodule update init 2> update.out &&
483 test_i18ngrep "not initialized" update.out &&
484 test_must_fail git rev-parse --resolve-git-dir init/.git &&
486 git submodule update --init init &&
487 git rev-parse --resolve-git-dir init/.git
490 test_expect_success 'update --init from subdirectory' '
492 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
493 git config --remove-section submodule.example &&
494 test_must_fail git config submodule.example.url &&
499 git submodule update ../init 2>update.out &&
501 test_i18ngrep "not initialized" update.out &&
502 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
504 git submodule update --init ../init
506 git rev-parse --resolve-git-dir init/.git
509 test_expect_success 'do not add files from a submodule' '
512 test_must_fail git add init/a
516 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
519 git commit -m "commit subproject" init &&
523 git diff --exit-code --cached init &&
525 git commit -m update a >/dev/null &&
526 git rev-parse HEAD) &&
528 test_must_fail git diff --exit-code --cached init &&
529 test $commit = $(git ls-files --stage |
530 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
532 git diff --exit-code --cached init
536 test_expect_success 'ls-files gracefully handles trailing slash' '
538 test "init" = "$(git ls-files init/)"
542 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
546 git checkout initial &&
551 test_expect_success 'submodule <invalid-subcommand> fails' '
552 test_must_fail git submodule no-such-subcommand
555 test_expect_success 'add submodules without specifying an explicit path' '
562 git commit -m "repo commit 1"
564 git clone --bare repo/ bare.git &&
567 git submodule add "$submodurl/repo" &&
568 git config -f .gitmodules submodule.repo.path repo &&
569 git submodule add "$submodurl/bare.git" &&
570 git config -f .gitmodules submodule.bare.path bare
574 test_expect_success 'add should fail when path is used by a file' '
578 test_must_fail git submodule add "$submodurl/repo" file
582 test_expect_success 'add should fail when path is used by an existing directory' '
586 test_must_fail git submodule add "$submodurl/repo" empty-dir
590 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
593 git submodule add ../repo relative &&
594 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
595 git submodule sync relative &&
596 test "$(git config submodule.relative.url)" = "$submodurl/repo"
600 test_expect_success 'set up for relative path tests' '
612 git config -f .gitmodules submodule.sub.path sub &&
613 git config -f .gitmodules submodule.sub.url ../subrepo &&
614 cp .git/config pristine-.git-config &&
615 cp .gitmodules pristine-.gitmodules
619 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
622 cp pristine-.git-config .git/config &&
623 cp pristine-.gitmodules .gitmodules &&
624 git config remote.origin.url ssh://hostname/repo &&
625 git submodule init &&
626 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
630 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
633 cp pristine-.git-config .git/config &&
634 cp pristine-.gitmodules .gitmodules &&
635 git config remote.origin.url ssh://hostname:22/repo &&
636 git submodule init &&
637 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
641 # About the choice of the path in the next test:
642 # - double-slash side-steps path mangling issues on Windows
643 # - it is still an absolute local path
644 # - there cannot be a server with a blank in its name just in case the
645 # path is used erroneously to access a //server/share style path
646 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
649 cp pristine-.git-config .git/config &&
650 cp pristine-.gitmodules .gitmodules &&
651 git config remote.origin.url "//somewhere else/repo" &&
652 git submodule init &&
653 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
657 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
660 cp pristine-.git-config .git/config &&
661 cp pristine-.gitmodules .gitmodules &&
662 git config remote.origin.url file:///tmp/repo &&
663 git submodule init &&
664 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
668 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
671 cp pristine-.git-config .git/config &&
672 cp pristine-.gitmodules .gitmodules &&
673 git config remote.origin.url helper:://hostname/repo &&
674 git submodule init &&
675 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
679 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
682 cp pristine-.git-config .git/config &&
683 git config remote.origin.url user@host:repo &&
684 git submodule init &&
685 test "$(git config submodule.sub.url)" = user@host:subrepo
689 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
692 cp pristine-.git-config .git/config &&
693 cp pristine-.gitmodules .gitmodules &&
694 git config remote.origin.url user@host:path/to/repo &&
695 git submodule init &&
696 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
700 test_expect_success '../subrepo works with relative local path - foo' '
703 cp pristine-.git-config .git/config &&
704 cp pristine-.gitmodules .gitmodules &&
705 git config remote.origin.url foo &&
706 # actual: fails with an error
707 git submodule init &&
708 test "$(git config submodule.sub.url)" = subrepo
712 test_expect_success '../subrepo works with relative local path - foo/bar' '
715 cp pristine-.git-config .git/config &&
716 cp pristine-.gitmodules .gitmodules &&
717 git config remote.origin.url foo/bar &&
718 git submodule init &&
719 test "$(git config submodule.sub.url)" = foo/subrepo
723 test_expect_success '../subrepo works with relative local path - ./foo' '
726 cp pristine-.git-config .git/config &&
727 cp pristine-.gitmodules .gitmodules &&
728 git config remote.origin.url ./foo &&
729 git submodule init &&
730 test "$(git config submodule.sub.url)" = subrepo
734 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
737 cp pristine-.git-config .git/config &&
738 cp pristine-.gitmodules .gitmodules &&
739 git config remote.origin.url ./foo/bar &&
740 git submodule init &&
741 test "$(git config submodule.sub.url)" = foo/subrepo
745 test_expect_success '../subrepo works with relative local path - ../foo' '
748 cp pristine-.git-config .git/config &&
749 cp pristine-.gitmodules .gitmodules &&
750 git config remote.origin.url ../foo &&
751 git submodule init &&
752 test "$(git config submodule.sub.url)" = ../subrepo
756 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
759 cp pristine-.git-config .git/config &&
760 cp pristine-.gitmodules .gitmodules &&
761 git config remote.origin.url ../foo/bar &&
762 git submodule init &&
763 test "$(git config submodule.sub.url)" = ../foo/subrepo
767 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
770 cp pristine-.git-config .git/config &&
771 cp pristine-.gitmodules .gitmodules &&
773 (cd a/b/c; git init) &&
774 git config remote.origin.url ../foo/bar.git &&
775 git submodule add ../bar/a/b/c ./a/b/c &&
776 git submodule init &&
777 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
781 test_expect_success 'moving the superproject does not break submodules' '
784 git submodule status >expect
786 mv addtest addtest2 &&
789 git submodule status >actual &&
790 test_cmp expect actual
794 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
799 echo "$submodurl/repo" >expect &&
800 git config remote.origin.url >actual &&
801 test_cmp expect actual &&
802 echo "gitdir: ../.git/modules/repo" >expect &&
807 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
808 test_must_be_empty actual &&
809 echo "gitdir: ../.git/modules/submod" >expect &&
810 test_cmp expect submod/.git &&
813 echo "$submodurl/bare.git" >expect &&
814 git config remote.origin.url >actual &&
815 test_cmp expect actual &&
816 echo "gitdir: ../.git/modules/repo_new" >expect &&
819 echo "repo" >expect &&
820 test_must_fail git config -f .gitmodules submodule.repo.path &&
821 git config -f .gitmodules submodule.repo_new.path >actual &&
822 test_cmp expect actual&&
823 echo "$submodurl/repo" >expect &&
824 test_must_fail git config -f .gitmodules submodule.repo.url &&
825 echo "$submodurl/bare.git" >expect &&
826 git config -f .gitmodules submodule.repo_new.url >actual &&
827 test_cmp expect actual &&
828 echo "$submodurl/repo" >expect &&
829 git config submodule.repo.url >actual &&
830 test_cmp expect actual &&
831 echo "$submodurl/bare.git" >expect &&
832 git config submodule.repo_new.url >actual &&
833 test_cmp expect actual
837 test_expect_success 'recursive relative submodules stay relative' '
838 test_when_finished "rm -rf super clone2 subsub sub3" &&
845 git commit -m "initial commit"
853 git commit -m "initial commit" &&
854 git submodule add ../subsub dirdir/subsub &&
855 git commit -m "add submodule subsub"
863 git commit -m "initial commit" &&
864 git submodule add ../sub3 &&
865 git commit -m "add submodule sub"
867 git clone super clone2 &&
870 git submodule update --init --recursive &&
871 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
872 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
874 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
875 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
878 test_expect_success 'submodule add with an existing name fails unless forced' '
883 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
885 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
886 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
887 echo "$submodurl/bare.git" >expect &&
888 git config submodule.repo_new.url >actual &&
889 test_cmp expect actual &&
890 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
892 echo "repo" >expect &&
893 git config -f .gitmodules submodule.repo_new.path >actual &&
894 test_cmp expect actual&&
895 echo "$submodurl/repo.git" >expect &&
896 git config -f .gitmodules submodule.repo_new.url >actual &&
897 test_cmp expect actual &&
898 echo "$submodurl/repo.git" >expect &&
899 git config submodule.repo_new.url >actual &&
900 test_cmp expect actual
904 test_expect_success 'set up a second submodule' '
905 git submodule add ./init2 example2 &&
906 git commit -m "submodule example2 added"
909 test_expect_success 'submodule deinit works on repository without submodules' '
910 test_when_finished "rm -rf newdirectory" &&
911 mkdir newdirectory &&
917 git commit -m "repo should not be empty" &&
918 git submodule deinit .
922 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
923 git config submodule.example.foo bar &&
924 git config submodule.example2.frotz nitfol &&
925 git submodule deinit init &&
926 test -z "$(git config --get-regexp "submodule\.example\.")" &&
927 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
928 test -f example2/.git &&
932 test_expect_success 'submodule deinit from subdirectory' '
933 git submodule update --init &&
934 git config submodule.example.foo bar &&
938 git submodule deinit ../init >../output
940 grep "\\.\\./init" output &&
941 test -z "$(git config --get-regexp "submodule\.example\.")" &&
942 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
943 test -f example2/.git &&
947 test_expect_success 'submodule deinit . deinits all initialized submodules' '
948 git submodule update --init &&
949 git config submodule.example.foo bar &&
950 git config submodule.example2.frotz nitfol &&
951 test_must_fail git submodule deinit &&
952 git submodule deinit . >actual &&
953 test -z "$(git config --get-regexp "submodule\.example\.")" &&
954 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
955 test_i18ngrep "Cleared directory .init" actual &&
956 test_i18ngrep "Cleared directory .example2" actual &&
960 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
961 git submodule update --init &&
962 rm -rf init example2/* example2/.git &&
963 git submodule deinit init example2 >actual &&
964 test -z "$(git config --get-regexp "submodule\.example\.")" &&
965 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
966 test_i18ngrep ! "Cleared directory .init" actual &&
967 test_i18ngrep "Cleared directory .example2" actual &&
971 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
972 git submodule update --init &&
974 test_must_fail git submodule deinit init &&
975 test -n "$(git config --get-regexp "submodule\.example\.")" &&
976 test -f example2/.git &&
977 git submodule deinit -f init >actual &&
978 test -z "$(git config --get-regexp "submodule\.example\.")" &&
979 test_i18ngrep "Cleared directory .init" actual &&
983 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
984 git submodule update --init &&
985 echo X >>init/untracked &&
986 test_must_fail git submodule deinit init &&
987 test -n "$(git config --get-regexp "submodule\.example\.")" &&
988 test -f example2/.git &&
989 git submodule deinit -f init >actual &&
990 test -z "$(git config --get-regexp "submodule\.example\.")" &&
991 test_i18ngrep "Cleared directory .init" actual &&
995 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
996 git submodule update --init &&
1001 test_must_fail git submodule deinit init &&
1002 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1003 test -f example2/.git &&
1004 git submodule deinit -f init >actual &&
1005 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1006 test_i18ngrep "Cleared directory .init" actual &&
1010 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1011 git submodule update --init &&
1012 git submodule deinit init >actual &&
1013 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1014 test_i18ngrep "Cleared directory .init" actual &&
1015 git submodule deinit init >actual &&
1016 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1017 test_i18ngrep "Cleared directory .init" actual &&
1018 git submodule deinit . >actual &&
1019 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1020 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1021 test_i18ngrep "Cleared directory .init" actual &&
1022 git submodule deinit . >actual &&
1023 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1024 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1025 test_i18ngrep "Cleared directory .init" actual &&
1029 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1030 git submodule update --init &&
1034 cp -R ../.git/modules/example .git &&
1035 GIT_WORK_TREE=. git config --unset core.worktree
1037 test_must_fail git submodule deinit init &&
1038 test_must_fail git submodule deinit -f init &&
1039 test -d init/.git &&
1040 test -n "$(git config --get-regexp "submodule\.example\.")"
1043 test_expect_success 'submodule with UTF-8 name' '
1044 svname=$(printf "\303\245 \303\244\303\266") &&
1051 git commit -m "init sub"
1053 git submodule add ./"$svname" &&
1054 git submodule >&2 &&
1055 test -n "$(git submodule | grep "$svname")"
1058 test_expect_success 'submodule add clone shallow submodule' '
1064 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1067 test 1 = $(git log --oneline | wc -l)
1072 test_expect_success 'submodule helper list is not confused by common prefixes' '
1077 echo hi >testfile2 &&
1079 git commit -m "test1"
1085 echo hello >testfile1 &&
1087 git commit -m "test2"
1089 git submodule add /dir1/b dir1/b &&
1090 git submodule add /dir2/b dir2/b &&
1091 git commit -m "first submodule commit" &&
1092 git submodule--helper list dir1/b |cut -c51- >actual &&
1093 echo "dir1/b" >expect &&
1094 test_cmp expect actual