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 --branch' '
156 echo "refs/heads/initial" >expect-head &&
157 cat <<-\EOF >expect-heads &&
165 git submodule add -b initial "$submodurl" submod-branch &&
166 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
170 rm -f heads head untracked &&
171 inspect addtest/submod-branch ../.. &&
172 test_cmp expect-heads heads &&
173 test_cmp expect-head head &&
174 test_cmp empty untracked
177 test_expect_success 'submodule add with ./ in path' '
178 echo "refs/heads/master" >expect &&
183 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
187 rm -f heads head untracked &&
188 inspect addtest/dotsubmod/frotz ../../.. &&
189 test_cmp expect heads &&
190 test_cmp expect head &&
191 test_cmp empty untracked
194 test_expect_success 'submodule add with /././ in path' '
195 echo "refs/heads/master" >expect &&
200 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
204 rm -f heads head untracked &&
205 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
206 test_cmp expect heads &&
207 test_cmp expect head &&
208 test_cmp empty untracked
211 test_expect_success 'submodule add with // in path' '
212 echo "refs/heads/master" >expect &&
217 git submodule add "$submodurl" slashslashsubmod///frotz// &&
221 rm -f heads head untracked &&
222 inspect addtest/slashslashsubmod/frotz ../../.. &&
223 test_cmp expect heads &&
224 test_cmp expect head &&
225 test_cmp empty untracked
228 test_expect_success 'submodule add with /.. in path' '
229 echo "refs/heads/master" >expect &&
234 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
238 rm -f heads head untracked &&
239 inspect addtest/realsubmod ../.. &&
240 test_cmp expect heads &&
241 test_cmp expect head &&
242 test_cmp empty untracked
245 test_expect_success 'submodule add with ./, /.. and // in path' '
246 echo "refs/heads/master" >expect &&
251 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
255 rm -f heads head untracked &&
256 inspect addtest/realsubmod2 ../.. &&
257 test_cmp expect heads &&
258 test_cmp expect head &&
259 test_cmp empty untracked
262 test_expect_success 'submodule add in subdirectory' '
263 echo "refs/heads/master" >expect &&
269 git submodule add "$submodurl" ../realsubmod3 &&
273 rm -f heads head untracked &&
274 inspect addtest/realsubmod3 ../.. &&
275 test_cmp expect heads &&
276 test_cmp expect head &&
277 test_cmp empty untracked
280 test_expect_success 'submodule add in subdirectory with relative path should fail' '
283 test_must_fail git submodule add ../../ submod3 2>../../output.err
285 test_i18ngrep toplevel output.err
288 test_expect_success 'setup - add an example entry to .gitmodules' '
289 git config --file=.gitmodules submodule.example.url git://example.com/init.git
292 test_expect_success 'status should fail for unmapped paths' '
293 test_must_fail git submodule status
296 test_expect_success 'setup - map path in .gitmodules' '
297 cat <<\EOF >expect &&
298 [submodule "example"]
299 url = git://example.com/init.git
303 git config --file=.gitmodules submodule.example.path init &&
305 test_cmp expect .gitmodules
308 test_expect_success 'status should only print one line' '
309 git submodule status >lines &&
310 test_line_count = 1 lines
313 test_expect_success 'setup - fetch commit name from submodule' '
314 rev1=$(cd .subrepo && git rev-parse HEAD) &&
315 printf "rev1: %s\n" "$rev1" &&
319 test_expect_success 'status should initially be "missing"' '
320 git submodule status >lines &&
324 test_expect_success 'init should register submodule url in .git/config' '
325 echo git://example.com/init.git >expect &&
327 git submodule init &&
328 git config submodule.example.url >url &&
329 git config submodule.example.url ./.subrepo &&
334 test_failure_with_unknown_submodule () {
335 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
336 grep "^error: .*no-such-submodule" output.err
339 test_expect_success 'init should fail with unknown submodule' '
340 test_failure_with_unknown_submodule init
343 test_expect_success 'update should fail with unknown submodule' '
344 test_failure_with_unknown_submodule update
347 test_expect_success 'status should fail with unknown submodule' '
348 test_failure_with_unknown_submodule status
351 test_expect_success 'sync should fail with unknown submodule' '
352 test_failure_with_unknown_submodule sync
355 test_expect_success 'update should fail when path is used by a file' '
356 echo hello >expect &&
358 echo "hello" >init &&
359 test_must_fail git submodule update &&
364 test_expect_success 'update should fail when path is used by a nonempty directory' '
365 echo hello >expect &&
369 echo "hello" >init/a &&
371 test_must_fail git submodule update &&
373 test_cmp expect init/a
376 test_expect_success 'update should work when path is an empty dir' '
379 echo "$rev1" >expect &&
382 git submodule update -q >update.out &&
383 test_must_be_empty update.out &&
386 test_cmp expect head-sha1
389 test_expect_success 'status should be "up-to-date" after update' '
390 git submodule status >list &&
394 test_expect_success 'status "up-to-date" from subdirectory' '
398 git submodule status >../list
400 grep "^ $rev1" list &&
401 grep "\\.\\./init" list
404 test_expect_success 'status "up-to-date" from subdirectory with path' '
408 git submodule status ../init >../list
410 grep "^ $rev1" list &&
411 grep "\\.\\./init" list
414 test_expect_success 'status should be "modified" after submodule commit' '
419 git commit -m "submodule commit 2"
422 rev2=$(cd init && git rev-parse HEAD) &&
424 git submodule status >list &&
429 test_expect_success 'the --cached sha1 should be rev1' '
430 git submodule --cached status >list &&
434 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
436 grep "^+Subproject commit $rev2" diff
439 test_expect_success 'update should checkout rev1' '
441 echo "$rev1" >expect &&
443 git submodule update init &&
446 test_cmp expect head-sha1
449 test_expect_success 'status should be "up-to-date" after update' '
450 git submodule status >list &&
454 test_expect_success 'checkout superproject with subproject already present' '
455 git checkout initial &&
459 test_expect_success 'apply submodule diff' '
467 git commit -m "change subproject"
469 git update-index --add init &&
470 git commit -m "change init" &&
471 git format-patch -1 --stdout >P.diff &&
472 git checkout second &&
473 git apply --index P.diff &&
475 git diff --cached master >staged &&
476 test_cmp empty staged
479 test_expect_success 'update --init' '
481 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
482 git config --remove-section submodule.example &&
483 test_must_fail git config submodule.example.url &&
485 git submodule update init 2> update.out &&
487 test_i18ngrep "not initialized" update.out &&
488 test_must_fail git rev-parse --resolve-git-dir init/.git &&
490 git submodule update --init init &&
491 git rev-parse --resolve-git-dir init/.git
494 test_expect_success 'update --init from subdirectory' '
496 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
497 git config --remove-section submodule.example &&
498 test_must_fail git config submodule.example.url &&
503 git submodule update ../init 2>update.out &&
505 test_i18ngrep "not initialized" update.out &&
506 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
508 git submodule update --init ../init
510 git rev-parse --resolve-git-dir init/.git
513 test_expect_success 'do not add files from a submodule' '
516 test_must_fail git add init/a
520 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
523 git commit -m "commit subproject" init &&
527 git diff --exit-code --cached init &&
529 git commit -m update a >/dev/null &&
530 git rev-parse HEAD) &&
532 test_must_fail git diff --exit-code --cached init &&
533 test $commit = $(git ls-files --stage |
534 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
536 git diff --exit-code --cached init
540 test_expect_success 'ls-files gracefully handles trailing slash' '
542 test "init" = "$(git ls-files init/)"
546 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
550 git checkout initial &&
555 test_expect_success 'submodule <invalid-subcommand> fails' '
556 test_must_fail git submodule no-such-subcommand
559 test_expect_success 'add submodules without specifying an explicit path' '
566 git commit -m "repo commit 1"
568 git clone --bare repo/ bare.git &&
571 git submodule add "$submodurl/repo" &&
572 git config -f .gitmodules submodule.repo.path repo &&
573 git submodule add "$submodurl/bare.git" &&
574 git config -f .gitmodules submodule.bare.path bare
578 test_expect_success 'add should fail when path is used by a file' '
582 test_must_fail git submodule add "$submodurl/repo" file
586 test_expect_success 'add should fail when path is used by an existing directory' '
590 test_must_fail git submodule add "$submodurl/repo" empty-dir
594 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
597 git submodule add ../repo relative &&
598 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
599 git submodule sync relative &&
600 test "$(git config submodule.relative.url)" = "$submodurl/repo"
604 test_expect_success 'set up for relative path tests' '
616 git config -f .gitmodules submodule.sub.path sub &&
617 git config -f .gitmodules submodule.sub.url ../subrepo &&
618 cp .git/config pristine-.git-config &&
619 cp .gitmodules pristine-.gitmodules
623 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
626 cp pristine-.git-config .git/config &&
627 cp pristine-.gitmodules .gitmodules &&
628 git config remote.origin.url ssh://hostname/repo &&
629 git submodule init &&
630 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
634 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
637 cp pristine-.git-config .git/config &&
638 cp pristine-.gitmodules .gitmodules &&
639 git config remote.origin.url ssh://hostname:22/repo &&
640 git submodule init &&
641 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
645 # About the choice of the path in the next test:
646 # - double-slash side-steps path mangling issues on Windows
647 # - it is still an absolute local path
648 # - there cannot be a server with a blank in its name just in case the
649 # path is used erroneously to access a //server/share style path
650 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
653 cp pristine-.git-config .git/config &&
654 cp pristine-.gitmodules .gitmodules &&
655 git config remote.origin.url "//somewhere else/repo" &&
656 git submodule init &&
657 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
661 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
664 cp pristine-.git-config .git/config &&
665 cp pristine-.gitmodules .gitmodules &&
666 git config remote.origin.url file:///tmp/repo &&
667 git submodule init &&
668 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
672 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
675 cp pristine-.git-config .git/config &&
676 cp pristine-.gitmodules .gitmodules &&
677 git config remote.origin.url helper:://hostname/repo &&
678 git submodule init &&
679 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
683 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
686 cp pristine-.git-config .git/config &&
687 git config remote.origin.url user@host:repo &&
688 git submodule init &&
689 test "$(git config submodule.sub.url)" = user@host:subrepo
693 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
696 cp pristine-.git-config .git/config &&
697 cp pristine-.gitmodules .gitmodules &&
698 git config remote.origin.url user@host:path/to/repo &&
699 git submodule init &&
700 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
704 test_expect_success '../subrepo works with relative local path - foo' '
707 cp pristine-.git-config .git/config &&
708 cp pristine-.gitmodules .gitmodules &&
709 git config remote.origin.url foo &&
710 # actual: fails with an error
711 git submodule init &&
712 test "$(git config submodule.sub.url)" = subrepo
716 test_expect_success '../subrepo works with relative local path - foo/bar' '
719 cp pristine-.git-config .git/config &&
720 cp pristine-.gitmodules .gitmodules &&
721 git config remote.origin.url foo/bar &&
722 git submodule init &&
723 test "$(git config submodule.sub.url)" = foo/subrepo
727 test_expect_success '../subrepo works with relative local path - ./foo' '
730 cp pristine-.git-config .git/config &&
731 cp pristine-.gitmodules .gitmodules &&
732 git config remote.origin.url ./foo &&
733 git submodule init &&
734 test "$(git config submodule.sub.url)" = subrepo
738 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
741 cp pristine-.git-config .git/config &&
742 cp pristine-.gitmodules .gitmodules &&
743 git config remote.origin.url ./foo/bar &&
744 git submodule init &&
745 test "$(git config submodule.sub.url)" = foo/subrepo
749 test_expect_success '../subrepo works with relative local path - ../foo' '
752 cp pristine-.git-config .git/config &&
753 cp pristine-.gitmodules .gitmodules &&
754 git config remote.origin.url ../foo &&
755 git submodule init &&
756 test "$(git config submodule.sub.url)" = ../subrepo
760 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
763 cp pristine-.git-config .git/config &&
764 cp pristine-.gitmodules .gitmodules &&
765 git config remote.origin.url ../foo/bar &&
766 git submodule init &&
767 test "$(git config submodule.sub.url)" = ../foo/subrepo
771 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
774 cp pristine-.git-config .git/config &&
775 cp pristine-.gitmodules .gitmodules &&
777 (cd a/b/c; git init) &&
778 git config remote.origin.url ../foo/bar.git &&
779 git submodule add ../bar/a/b/c ./a/b/c &&
780 git submodule init &&
781 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
785 test_expect_success 'moving the superproject does not break submodules' '
788 git submodule status >expect
790 mv addtest addtest2 &&
793 git submodule status >actual &&
794 test_cmp expect actual
798 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
803 echo "$submodurl/repo" >expect &&
804 git config remote.origin.url >actual &&
805 test_cmp expect actual &&
806 echo "gitdir: ../.git/modules/repo" >expect &&
811 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
812 test_must_be_empty actual &&
813 echo "gitdir: ../.git/modules/submod" >expect &&
814 test_cmp expect submod/.git &&
817 echo "$submodurl/bare.git" >expect &&
818 git config remote.origin.url >actual &&
819 test_cmp expect actual &&
820 echo "gitdir: ../.git/modules/repo_new" >expect &&
823 echo "repo" >expect &&
824 test_must_fail git config -f .gitmodules submodule.repo.path &&
825 git config -f .gitmodules submodule.repo_new.path >actual &&
826 test_cmp expect actual&&
827 echo "$submodurl/repo" >expect &&
828 test_must_fail git config -f .gitmodules submodule.repo.url &&
829 echo "$submodurl/bare.git" >expect &&
830 git config -f .gitmodules submodule.repo_new.url >actual &&
831 test_cmp expect actual &&
832 echo "$submodurl/repo" >expect &&
833 git config submodule.repo.url >actual &&
834 test_cmp expect actual &&
835 echo "$submodurl/bare.git" >expect &&
836 git config submodule.repo_new.url >actual &&
837 test_cmp expect actual
841 test_expect_success 'recursive relative submodules stay relative' '
842 test_when_finished "rm -rf super clone2 subsub sub3" &&
849 git commit -m "initial commit"
857 git commit -m "initial commit" &&
858 git submodule add ../subsub dirdir/subsub &&
859 git commit -m "add submodule subsub"
867 git commit -m "initial commit" &&
868 git submodule add ../sub3 &&
869 git commit -m "add submodule sub"
871 git clone super clone2 &&
874 git submodule update --init --recursive &&
875 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
876 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
878 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
879 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
882 test_expect_success 'submodule add with an existing name fails unless forced' '
887 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
889 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
890 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
891 echo "$submodurl/bare.git" >expect &&
892 git config submodule.repo_new.url >actual &&
893 test_cmp expect actual &&
894 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
896 echo "repo" >expect &&
897 git config -f .gitmodules submodule.repo_new.path >actual &&
898 test_cmp expect actual&&
899 echo "$submodurl/repo.git" >expect &&
900 git config -f .gitmodules submodule.repo_new.url >actual &&
901 test_cmp expect actual &&
902 echo "$submodurl/repo.git" >expect &&
903 git config submodule.repo_new.url >actual &&
904 test_cmp expect actual
908 test_expect_success 'set up a second submodule' '
909 git submodule add ./init2 example2 &&
910 git commit -m "submodule example2 added"
913 test_expect_success 'submodule deinit works on repository without submodules' '
914 test_when_finished "rm -rf newdirectory" &&
915 mkdir newdirectory &&
921 git commit -m "repo should not be empty" &&
922 git submodule deinit . &&
923 git submodule deinit --all
927 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
928 git config submodule.example.foo bar &&
929 git config submodule.example2.frotz nitfol &&
930 git submodule deinit init &&
931 test -z "$(git config --get-regexp "submodule\.example\.")" &&
932 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
933 test -f example2/.git &&
937 test_expect_success 'submodule deinit from subdirectory' '
938 git submodule update --init &&
939 git config submodule.example.foo bar &&
943 git submodule deinit ../init >../output
945 test_i18ngrep "\\.\\./init" output &&
946 test -z "$(git config --get-regexp "submodule\.example\.")" &&
947 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
948 test -f example2/.git &&
952 test_expect_success 'submodule deinit . deinits all initialized submodules' '
953 git submodule update --init &&
954 git config submodule.example.foo bar &&
955 git config submodule.example2.frotz nitfol &&
956 test_must_fail git submodule deinit &&
957 git submodule deinit . >actual &&
958 test -z "$(git config --get-regexp "submodule\.example\.")" &&
959 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
960 test_i18ngrep "Cleared directory .init" actual &&
961 test_i18ngrep "Cleared directory .example2" actual &&
965 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
966 git submodule update --init &&
967 git config submodule.example.foo bar &&
968 git config submodule.example2.frotz nitfol &&
969 test_must_fail git submodule deinit &&
970 git submodule deinit --all >actual &&
971 test -z "$(git config --get-regexp "submodule\.example\.")" &&
972 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
973 test_i18ngrep "Cleared directory .init" actual &&
974 test_i18ngrep "Cleared directory .example2" actual &&
978 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
979 git submodule update --init &&
980 rm -rf init example2/* example2/.git &&
981 git submodule deinit init example2 >actual &&
982 test -z "$(git config --get-regexp "submodule\.example\.")" &&
983 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
984 test_i18ngrep ! "Cleared directory .init" actual &&
985 test_i18ngrep "Cleared directory .example2" actual &&
989 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
990 git submodule update --init &&
992 test_must_fail git submodule deinit init &&
993 test -n "$(git config --get-regexp "submodule\.example\.")" &&
994 test -f example2/.git &&
995 git submodule deinit -f init >actual &&
996 test -z "$(git config --get-regexp "submodule\.example\.")" &&
997 test_i18ngrep "Cleared directory .init" actual &&
1001 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
1002 git submodule update --init &&
1003 echo X >>init/untracked &&
1004 test_must_fail git submodule deinit init &&
1005 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1006 test -f example2/.git &&
1007 git submodule deinit -f init >actual &&
1008 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1009 test_i18ngrep "Cleared directory .init" actual &&
1013 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
1014 git submodule update --init &&
1019 test_must_fail git submodule deinit init &&
1020 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1021 test -f example2/.git &&
1022 git submodule deinit -f init >actual &&
1023 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1024 test_i18ngrep "Cleared directory .init" actual &&
1028 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1029 git submodule update --init &&
1030 git submodule deinit init >actual &&
1031 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1032 test_i18ngrep "Cleared directory .init" actual &&
1033 git submodule deinit init >actual &&
1034 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1035 test_i18ngrep "Cleared directory .init" actual &&
1036 git submodule deinit . >actual &&
1037 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1038 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1039 test_i18ngrep "Cleared directory .init" actual &&
1040 git submodule deinit . >actual &&
1041 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1042 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1043 test_i18ngrep "Cleared directory .init" actual &&
1044 git submodule deinit --all >actual &&
1045 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1046 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1047 test_i18ngrep "Cleared directory .init" actual &&
1051 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
1052 git submodule update --init &&
1056 cp -R ../.git/modules/example .git &&
1057 GIT_WORK_TREE=. git config --unset core.worktree
1059 test_must_fail git submodule deinit init &&
1060 test_must_fail git submodule deinit -f init &&
1061 test -d init/.git &&
1062 test -n "$(git config --get-regexp "submodule\.example\.")"
1065 test_expect_success 'submodule with UTF-8 name' '
1066 svname=$(printf "\303\245 \303\244\303\266") &&
1073 git commit -m "init sub"
1075 git submodule add ./"$svname" &&
1076 git submodule >&2 &&
1077 test -n "$(git submodule | grep "$svname")"
1080 test_expect_success 'submodule add clone shallow submodule' '
1086 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1089 test 1 = $(git log --oneline | wc -l)
1094 test_expect_success 'submodule helper list is not confused by common prefixes' '
1099 echo hi >testfile2 &&
1101 git commit -m "test1"
1107 echo hello >testfile1 &&
1109 git commit -m "test2"
1111 git submodule add /dir1/b dir1/b &&
1112 git submodule add /dir2/b dir2/b &&
1113 git commit -m "first submodule commit" &&
1114 git submodule--helper list dir1/b |cut -c51- >actual &&
1115 echo "dir1/b" >expect &&
1116 test_cmp expect actual