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
'configuration parsing' '
42 test_when_finished "rm -f .gitmodules" &&
43 cat >.gitmodules <<-\EOF &&
48 test_must_fail git status
51 test_expect_success
'setup - repository in init subdirectory' '
58 git commit -m "submodule commit 1" &&
59 git tag -a -m "rev-1" rev-1
63 test_expect_success
'setup - commit with gitlink' '
67 git commit -m "super commit 1"
70 test_expect_success
'setup - hide init subdirectory' '
74 test_expect_success
'setup - repository to add submodules to' '
76 git init addtest-ignore
79 # The 'submodule add' tests need some repository to add as a submodule.
80 # The trash directory is a good one as any. We need to canonicalize
81 # the name, though, as some tests compare it to the absolute path git
82 # generates, which will expand symbolic links.
86 git for-each-ref
--format='%(refname)' 'refs/heads/*'
95 listbranches
>"$dotdot/heads" &&
96 { git symbolic-ref HEAD ||
:; } >"$dotdot/head" &&
97 git rev-parse HEAD
>"$dotdot/head-sha1" &&
98 git update-index
--refresh &&
99 git diff-files
--exit-code &&
100 git clean
-n -d -x >"$dotdot/untracked"
104 test_expect_success
'submodule add' '
105 echo "refs/heads/master" >expect &&
110 git submodule add -q "$submodurl" submod >actual &&
111 test_must_be_empty actual &&
112 echo "gitdir: ../.git/modules/submod" >expect &&
113 test_cmp expect submod/.git &&
116 git config core.worktree >actual &&
117 echo "../../../submod" >expect &&
118 test_cmp expect actual &&
124 rm -f heads head untracked &&
125 inspect addtest/submod ../.. &&
126 test_cmp expect heads &&
127 test_cmp expect head &&
128 test_cmp empty untracked
131 test_expect_success
'submodule add to .gitignored path fails' '
134 cat <<-\EOF >expect &&
135 The following path is ignored by one of your .gitignore files:
137 Use -f if you really want to add it.
139 # Does not use test_commit due to the ignore
140 echo "*" > .gitignore &&
141 git add --force .gitignore &&
142 git commit -m"Ignore everything" &&
143 ! git submodule add "$submodurl" submod >actual 2>&1 &&
144 test_i18ncmp expect actual
148 test_expect_success
'submodule add to .gitignored path with --force' '
151 git submodule add --force "$submodurl" submod
155 test_expect_success
'submodule add to reconfigure existing submodule with --force' '
158 git submodule add --force bogus-url submod &&
159 git submodule add -b initial "$submodurl" submod-branch &&
160 test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
161 test "bogus-url" = "$(git config submodule.submod.url)" &&
163 git submodule add --force "$submodurl" submod
164 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
165 test "$submodurl" = "$(git config submodule.submod.url)"
169 test_expect_success
'submodule add --branch' '
170 echo "refs/heads/initial" >expect-head &&
171 cat <<-\EOF >expect-heads &&
179 git submodule add -b initial "$submodurl" submod-branch &&
180 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
184 rm -f heads head untracked &&
185 inspect addtest/submod-branch ../.. &&
186 test_cmp expect-heads heads &&
187 test_cmp expect-head head &&
188 test_cmp empty untracked
191 test_expect_success
'submodule add with ./ in path' '
192 echo "refs/heads/master" >expect &&
197 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
201 rm -f heads head untracked &&
202 inspect addtest/dotsubmod/frotz ../../.. &&
203 test_cmp expect heads &&
204 test_cmp expect head &&
205 test_cmp empty untracked
208 test_expect_success
'submodule add with /././ in path' '
209 echo "refs/heads/master" >expect &&
214 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
218 rm -f heads head untracked &&
219 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
220 test_cmp expect heads &&
221 test_cmp expect head &&
222 test_cmp empty untracked
225 test_expect_success
'submodule add with // in path' '
226 echo "refs/heads/master" >expect &&
231 git submodule add "$submodurl" slashslashsubmod///frotz// &&
235 rm -f heads head untracked &&
236 inspect addtest/slashslashsubmod/frotz ../../.. &&
237 test_cmp expect heads &&
238 test_cmp expect head &&
239 test_cmp empty untracked
242 test_expect_success
'submodule add with /.. in path' '
243 echo "refs/heads/master" >expect &&
248 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
252 rm -f heads head untracked &&
253 inspect addtest/realsubmod ../.. &&
254 test_cmp expect heads &&
255 test_cmp expect head &&
256 test_cmp empty untracked
259 test_expect_success
'submodule add with ./, /.. and // in path' '
260 echo "refs/heads/master" >expect &&
265 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
269 rm -f heads head untracked &&
270 inspect addtest/realsubmod2 ../.. &&
271 test_cmp expect heads &&
272 test_cmp expect head &&
273 test_cmp empty untracked
276 test_expect_success
'submodule add in subdirectory' '
277 echo "refs/heads/master" >expect &&
283 git submodule add "$submodurl" ../realsubmod3 &&
287 rm -f heads head untracked &&
288 inspect addtest/realsubmod3 ../.. &&
289 test_cmp expect heads &&
290 test_cmp expect head &&
291 test_cmp empty untracked
294 test_expect_success
'submodule add in subdirectory with relative path should fail' '
297 test_must_fail git submodule add ../../ submod3 2>../../output.err
299 test_i18ngrep toplevel output.err
302 test_expect_success
'setup - add an example entry to .gitmodules' '
303 git config --file=.gitmodules submodule.example.url git://example.com/init.git
306 test_expect_success
'status should fail for unmapped paths' '
307 test_must_fail git submodule status
310 test_expect_success
'setup - map path in .gitmodules' '
311 cat <<\EOF >expect &&
312 [submodule "example"]
313 url = git://example.com/init.git
317 git config --file=.gitmodules submodule.example.path init &&
319 test_cmp expect .gitmodules
322 test_expect_success
'status should only print one line' '
323 git submodule status >lines &&
324 test_line_count = 1 lines
327 test_expect_success
'setup - fetch commit name from submodule' '
328 rev1=$(cd .subrepo && git rev-parse HEAD) &&
329 printf "rev1: %s\n" "$rev1" &&
333 test_expect_success
'status should initially be "missing"' '
334 git submodule status >lines &&
338 test_expect_success
'init should register submodule url in .git/config' '
339 echo git://example.com/init.git >expect &&
341 git submodule init &&
342 git config submodule.example.url >url &&
343 git config submodule.example.url ./.subrepo &&
348 test_failure_with_unknown_submodule
() {
349 test_must_fail git submodule
$1 no-such-submodule
2>output.err
&&
350 grep "^error: .*no-such-submodule" output.err
353 test_expect_success
'init should fail with unknown submodule' '
354 test_failure_with_unknown_submodule init
357 test_expect_success
'update should fail with unknown submodule' '
358 test_failure_with_unknown_submodule update
361 test_expect_success
'status should fail with unknown submodule' '
362 test_failure_with_unknown_submodule status
365 test_expect_success
'sync should fail with unknown submodule' '
366 test_failure_with_unknown_submodule sync
369 test_expect_success
'update should fail when path is used by a file' '
370 echo hello >expect &&
372 echo "hello" >init &&
373 test_must_fail git submodule update &&
378 test_expect_success
'update should fail when path is used by a nonempty directory' '
379 echo hello >expect &&
383 echo "hello" >init/a &&
385 test_must_fail git submodule update &&
387 test_cmp expect init/a
390 test_expect_success
'update should work when path is an empty dir' '
393 echo "$rev1" >expect &&
396 git submodule update -q >update.out &&
397 test_must_be_empty update.out &&
400 test_cmp expect head-sha1
403 test_expect_success
'status should be "up-to-date" after update' '
404 git submodule status >list &&
408 test_expect_success
'status "up-to-date" from subdirectory' '
412 git submodule status >../list
414 grep "^ $rev1" list &&
415 grep "\\.\\./init" list
418 test_expect_success
'status "up-to-date" from subdirectory with path' '
422 git submodule status ../init >../list
424 grep "^ $rev1" list &&
425 grep "\\.\\./init" list
428 test_expect_success
'status should be "modified" after submodule commit' '
433 git commit -m "submodule commit 2"
436 rev2=$(cd init && git rev-parse HEAD) &&
438 git submodule status >list &&
443 test_expect_success
'the --cached sha1 should be rev1' '
444 git submodule --cached status >list &&
448 test_expect_success
'git diff should report the SHA1 of the new submodule commit' '
450 grep "^+Subproject commit $rev2" diff
453 test_expect_success
'update should checkout rev1' '
455 echo "$rev1" >expect &&
457 git submodule update init &&
460 test_cmp expect head-sha1
463 test_expect_success
'status should be "up-to-date" after update' '
464 git submodule status >list &&
468 test_expect_success
'checkout superproject with subproject already present' '
469 git checkout initial &&
473 test_expect_success
'apply submodule diff' '
481 git commit -m "change subproject"
483 git update-index --add init &&
484 git commit -m "change init" &&
485 git format-patch -1 --stdout >P.diff &&
486 git checkout second &&
487 git apply --index P.diff &&
489 git diff --cached master >staged &&
490 test_cmp empty staged
493 test_expect_success
'update --init' '
495 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
496 git config --remove-section submodule.example &&
497 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 &&
505 git rev-parse --resolve-git-dir init/.git
508 test_expect_success
'update --init from subdirectory' '
510 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
511 git config --remove-section submodule.example &&
512 test_must_fail git config submodule.example.url &&
517 git submodule update ../init 2>update.out &&
519 test_i18ngrep "not initialized" update.out &&
520 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
522 git submodule update --init ../init
524 git rev-parse --resolve-git-dir init/.git
527 test_expect_success
'do not add files from a submodule' '
530 test_must_fail git add init/a
534 test_expect_success
'gracefully add/reset submodule with a trailing slash' '
537 git commit -m "commit subproject" init &&
541 git diff --exit-code --cached init &&
543 git commit -m update a >/dev/null &&
544 git rev-parse HEAD) &&
546 test_must_fail git diff --exit-code --cached init &&
547 test $commit = $(git ls-files --stage |
548 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
550 git diff --exit-code --cached init
554 test_expect_success
'ls-files gracefully handles trailing slash' '
556 test "init" = "$(git ls-files init/)"
560 test_expect_success
'moving to a commit without submodule does not leave empty dir' '
564 git checkout initial &&
569 test_expect_success
'submodule <invalid-subcommand> fails' '
570 test_must_fail git submodule no-such-subcommand
573 test_expect_success
'add submodules without specifying an explicit path' '
580 git commit -m "repo commit 1"
582 git clone --bare repo/ bare.git &&
585 git submodule add "$submodurl/repo" &&
586 git config -f .gitmodules submodule.repo.path repo &&
587 git submodule add "$submodurl/bare.git" &&
588 git config -f .gitmodules submodule.bare.path bare
592 test_expect_success
'add should fail when path is used by a file' '
596 test_must_fail git submodule add "$submodurl/repo" file
600 test_expect_success
'add should fail when path is used by an existing directory' '
604 test_must_fail git submodule add "$submodurl/repo" empty-dir
608 test_expect_success
'use superproject as upstream when path is relative and no url is set there' '
611 git submodule add ../repo relative &&
612 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
613 git submodule sync relative &&
614 test "$(git config submodule.relative.url)" = "$submodurl/repo"
618 test_expect_success
'set up for relative path tests' '
630 git config -f .gitmodules submodule.sub.path sub &&
631 git config -f .gitmodules submodule.sub.url ../subrepo &&
632 cp .git/config pristine-.git-config &&
633 cp .gitmodules pristine-.gitmodules
637 test_expect_success
'../subrepo works with URL - ssh://hostname/repo' '
640 cp pristine-.git-config .git/config &&
641 cp pristine-.gitmodules .gitmodules &&
642 git config remote.origin.url ssh://hostname/repo &&
643 git submodule init &&
644 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
648 test_expect_success
'../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
651 cp pristine-.git-config .git/config &&
652 cp pristine-.gitmodules .gitmodules &&
653 git config remote.origin.url ssh://hostname:22/repo &&
654 git submodule init &&
655 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
659 # About the choice of the path in the next test:
660 # - double-slash side-steps path mangling issues on Windows
661 # - it is still an absolute local path
662 # - there cannot be a server with a blank in its name just in case the
663 # path is used erroneously to access a //server/share style path
664 test_expect_success
'../subrepo path works with local path - //somewhere else/repo' '
667 cp pristine-.git-config .git/config &&
668 cp pristine-.gitmodules .gitmodules &&
669 git config remote.origin.url "//somewhere else/repo" &&
670 git submodule init &&
671 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
675 test_expect_success
'../subrepo works with file URL - file:///tmp/repo' '
678 cp pristine-.git-config .git/config &&
679 cp pristine-.gitmodules .gitmodules &&
680 git config remote.origin.url file:///tmp/repo &&
681 git submodule init &&
682 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
686 test_expect_success
'../subrepo works with helper URL- helper:://hostname/repo' '
689 cp pristine-.git-config .git/config &&
690 cp pristine-.gitmodules .gitmodules &&
691 git config remote.origin.url helper:://hostname/repo &&
692 git submodule init &&
693 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
697 test_expect_success
'../subrepo works with scp-style URL - user@host:repo' '
700 cp pristine-.git-config .git/config &&
701 git config remote.origin.url user@host:repo &&
702 git submodule init &&
703 test "$(git config submodule.sub.url)" = user@host:subrepo
707 test_expect_success
'../subrepo works with scp-style URL - user@host:path/to/repo' '
710 cp pristine-.git-config .git/config &&
711 cp pristine-.gitmodules .gitmodules &&
712 git config remote.origin.url user@host:path/to/repo &&
713 git submodule init &&
714 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
718 test_expect_success
'../subrepo works with relative local path - foo' '
721 cp pristine-.git-config .git/config &&
722 cp pristine-.gitmodules .gitmodules &&
723 git config remote.origin.url foo &&
724 # actual: fails with an error
725 git submodule init &&
726 test "$(git config submodule.sub.url)" = subrepo
730 test_expect_success
'../subrepo works with relative local path - foo/bar' '
733 cp pristine-.git-config .git/config &&
734 cp pristine-.gitmodules .gitmodules &&
735 git config remote.origin.url foo/bar &&
736 git submodule init &&
737 test "$(git config submodule.sub.url)" = foo/subrepo
741 test_expect_success
'../subrepo works with relative local path - ./foo' '
744 cp pristine-.git-config .git/config &&
745 cp pristine-.gitmodules .gitmodules &&
746 git config remote.origin.url ./foo &&
747 git submodule init &&
748 test "$(git config submodule.sub.url)" = subrepo
752 test_expect_success
'../subrepo works with relative local path - ./foo/bar' '
755 cp pristine-.git-config .git/config &&
756 cp pristine-.gitmodules .gitmodules &&
757 git config remote.origin.url ./foo/bar &&
758 git submodule init &&
759 test "$(git config submodule.sub.url)" = foo/subrepo
763 test_expect_success
'../subrepo works with relative local path - ../foo' '
766 cp pristine-.git-config .git/config &&
767 cp pristine-.gitmodules .gitmodules &&
768 git config remote.origin.url ../foo &&
769 git submodule init &&
770 test "$(git config submodule.sub.url)" = ../subrepo
774 test_expect_success
'../subrepo works with relative local path - ../foo/bar' '
777 cp pristine-.git-config .git/config &&
778 cp pristine-.gitmodules .gitmodules &&
779 git config remote.origin.url ../foo/bar &&
780 git submodule init &&
781 test "$(git config submodule.sub.url)" = ../foo/subrepo
785 test_expect_success
'../bar/a/b/c works with relative local path - ../foo/bar.git' '
788 cp pristine-.git-config .git/config &&
789 cp pristine-.gitmodules .gitmodules &&
791 (cd a/b/c; git init) &&
792 git config remote.origin.url ../foo/bar.git &&
793 git submodule add ../bar/a/b/c ./a/b/c &&
794 git submodule init &&
795 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
799 test_expect_success
'moving the superproject does not break submodules' '
802 git submodule status >expect
804 mv addtest addtest2 &&
807 git submodule status >actual &&
808 test_cmp expect actual
812 test_expect_success
'submodule add --name allows to replace a submodule with another at the same path' '
817 echo "$submodurl/repo" >expect &&
818 git config remote.origin.url >actual &&
819 test_cmp expect actual &&
820 echo "gitdir: ../.git/modules/repo" >expect &&
825 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
826 test_must_be_empty actual &&
827 echo "gitdir: ../.git/modules/submod" >expect &&
828 test_cmp expect submod/.git &&
831 echo "$submodurl/bare.git" >expect &&
832 git config remote.origin.url >actual &&
833 test_cmp expect actual &&
834 echo "gitdir: ../.git/modules/repo_new" >expect &&
837 echo "repo" >expect &&
838 test_must_fail git config -f .gitmodules submodule.repo.path &&
839 git config -f .gitmodules submodule.repo_new.path >actual &&
840 test_cmp expect actual&&
841 echo "$submodurl/repo" >expect &&
842 test_must_fail git config -f .gitmodules submodule.repo.url &&
843 echo "$submodurl/bare.git" >expect &&
844 git config -f .gitmodules submodule.repo_new.url >actual &&
845 test_cmp expect actual &&
846 echo "$submodurl/repo" >expect &&
847 git config submodule.repo.url >actual &&
848 test_cmp expect actual &&
849 echo "$submodurl/bare.git" >expect &&
850 git config submodule.repo_new.url >actual &&
851 test_cmp expect actual
855 test_expect_success
'recursive relative submodules stay relative' '
856 test_when_finished "rm -rf super clone2 subsub sub3" &&
863 git commit -m "initial commit"
871 git commit -m "initial commit" &&
872 git submodule add ../subsub dirdir/subsub &&
873 git commit -m "add submodule subsub"
881 git commit -m "initial commit" &&
882 git submodule add ../sub3 &&
883 git commit -m "add submodule sub"
885 git clone super clone2 &&
888 git submodule update --init --recursive &&
889 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
890 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
892 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
893 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
896 test_expect_success
'submodule add with an existing name fails unless forced' '
901 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
903 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
904 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
905 echo "$submodurl/bare.git" >expect &&
906 git config submodule.repo_new.url >actual &&
907 test_cmp expect actual &&
908 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
910 echo "repo" >expect &&
911 git config -f .gitmodules submodule.repo_new.path >actual &&
912 test_cmp expect actual&&
913 echo "$submodurl/repo.git" >expect &&
914 git config -f .gitmodules submodule.repo_new.url >actual &&
915 test_cmp expect actual &&
916 echo "$submodurl/repo.git" >expect &&
917 git config submodule.repo_new.url >actual &&
918 test_cmp expect actual
922 test_expect_success
'set up a second submodule' '
923 git submodule add ./init2 example2 &&
924 git commit -m "submodule example2 added"
927 test_expect_success
'submodule deinit works on repository without submodules' '
928 test_when_finished "rm -rf newdirectory" &&
929 mkdir newdirectory &&
935 git commit -m "repo should not be empty" &&
936 git submodule deinit . &&
937 git submodule deinit --all
941 test_expect_success
'submodule deinit should remove the whole submodule section from .git/config' '
942 git config submodule.example.foo bar &&
943 git config submodule.example2.frotz nitfol &&
944 git submodule deinit init &&
945 test -z "$(git config --get-regexp "submodule\.example\.")" &&
946 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
947 test -f example2/.git &&
951 test_expect_success
'submodule deinit from subdirectory' '
952 git submodule update --init &&
953 git config submodule.example.foo bar &&
957 git submodule deinit ../init >../output
959 test_i18ngrep "\\.\\./init" output &&
960 test -z "$(git config --get-regexp "submodule\.example\.")" &&
961 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
962 test -f example2/.git &&
966 test_expect_success
'submodule deinit . deinits all initialized submodules' '
967 git submodule update --init &&
968 git config submodule.example.foo bar &&
969 git config submodule.example2.frotz nitfol &&
970 test_must_fail git submodule deinit &&
971 git submodule deinit . >actual &&
972 test -z "$(git config --get-regexp "submodule\.example\.")" &&
973 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
974 test_i18ngrep "Cleared directory .init" actual &&
975 test_i18ngrep "Cleared directory .example2" actual &&
979 test_expect_success
'submodule deinit --all deinits all initialized submodules' '
980 git submodule update --init &&
981 git config submodule.example.foo bar &&
982 git config submodule.example2.frotz nitfol &&
983 test_must_fail git submodule deinit &&
984 git submodule deinit --all >actual &&
985 test -z "$(git config --get-regexp "submodule\.example\.")" &&
986 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
987 test_i18ngrep "Cleared directory .init" actual &&
988 test_i18ngrep "Cleared directory .example2" actual &&
992 test_expect_success
'submodule deinit deinits a submodule when its work tree is missing or empty' '
993 git submodule update --init &&
994 rm -rf init example2/* example2/.git &&
995 git submodule deinit init example2 >actual &&
996 test -z "$(git config --get-regexp "submodule\.example\.")" &&
997 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
998 test_i18ngrep ! "Cleared directory .init" actual &&
999 test_i18ngrep "Cleared directory .example2" actual &&
1003 test_expect_success
'submodule deinit fails when the submodule contains modifications unless forced' '
1004 git submodule update --init &&
1006 test_must_fail git submodule deinit init &&
1007 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1008 test -f example2/.git &&
1009 git submodule deinit -f init >actual &&
1010 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1011 test_i18ngrep "Cleared directory .init" actual &&
1015 test_expect_success
'submodule deinit fails when the submodule contains untracked files unless forced' '
1016 git submodule update --init &&
1017 echo X >>init/untracked &&
1018 test_must_fail git submodule deinit init &&
1019 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1020 test -f example2/.git &&
1021 git submodule deinit -f init >actual &&
1022 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1023 test_i18ngrep "Cleared directory .init" actual &&
1027 test_expect_success
'submodule deinit fails when the submodule HEAD does not match unless forced' '
1028 git submodule update --init &&
1033 test_must_fail git submodule deinit init &&
1034 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1035 test -f example2/.git &&
1036 git submodule deinit -f init >actual &&
1037 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1038 test_i18ngrep "Cleared directory .init" actual &&
1042 test_expect_success
'submodule deinit is silent when used on an uninitialized submodule' '
1043 git submodule update --init &&
1044 git submodule deinit init >actual &&
1045 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1046 test_i18ngrep "Cleared directory .init" actual &&
1047 git submodule deinit init >actual &&
1048 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1049 test_i18ngrep "Cleared directory .init" actual &&
1050 git submodule deinit . >actual &&
1051 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1052 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1053 test_i18ngrep "Cleared directory .init" actual &&
1054 git submodule deinit . >actual &&
1055 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1056 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1057 test_i18ngrep "Cleared directory .init" actual &&
1058 git submodule deinit --all >actual &&
1059 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1060 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1061 test_i18ngrep "Cleared directory .init" actual &&
1065 test_expect_success
'submodule deinit fails when submodule has a .git directory even when forced' '
1066 git submodule update --init &&
1070 cp -R ../.git/modules/example .git &&
1071 GIT_WORK_TREE=. git config --unset core.worktree
1073 test_must_fail git submodule deinit init &&
1074 test_must_fail git submodule deinit -f init &&
1075 test -d init/.git &&
1076 test -n "$(git config --get-regexp "submodule\.example\.")"
1079 test_expect_success
'submodule with UTF-8 name' '
1080 svname=$(printf "\303\245 \303\244\303\266") &&
1087 git commit -m "init sub"
1089 git submodule add ./"$svname" &&
1090 git submodule >&2 &&
1091 test -n "$(git submodule | grep "$svname")"
1094 test_expect_success
'submodule add clone shallow submodule' '
1100 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1103 test 1 = $(git log --oneline | wc -l)
1108 test_expect_success
'submodule helper list is not confused by common prefixes' '
1113 echo hi >testfile2 &&
1115 git commit -m "test1"
1121 echo hello >testfile1 &&
1123 git commit -m "test2"
1125 git submodule add /dir1/b dir1/b &&
1126 git submodule add /dir2/b dir2/b &&
1127 git commit -m "first submodule commit" &&
1128 git submodule--helper list dir1/b |cut -c51- >actual &&
1129 echo "dir1/b" >expect &&
1130 test_cmp expect actual