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
'configuration parsing' '
50 test_when_finished "rm -f .gitmodules" &&
51 cat >.gitmodules <<-\EOF &&
56 test_must_fail git status
59 test_expect_success
'setup - repository in init subdirectory' '
66 git commit -m "submodule commit 1" &&
67 git tag -a -m "rev-1" rev-1
71 test_expect_success
'setup - commit with gitlink' '
75 git commit -m "super commit 1"
78 test_expect_success
'setup - hide init subdirectory' '
82 test_expect_success
'setup - repository to add submodules to' '
84 git init addtest-ignore
87 # The 'submodule add' tests need some repository to add as a submodule.
88 # The trash directory is a good one as any. We need to canonicalize
89 # the name, though, as some tests compare it to the absolute path git
90 # generates, which will expand symbolic links.
94 git for-each-ref
--format='%(refname)' 'refs/heads/*'
103 listbranches
>"$dotdot/heads" &&
104 { git symbolic-ref HEAD ||
:; } >"$dotdot/head" &&
105 git rev-parse HEAD
>"$dotdot/head-sha1" &&
106 git update-index
--refresh &&
107 git diff-files
--exit-code &&
108 git clean
-n -d -x >"$dotdot/untracked"
112 test_expect_success
'submodule add' '
113 echo "refs/heads/master" >expect &&
118 git submodule add -q "$submodurl" submod >actual &&
119 test_must_be_empty actual &&
120 echo "gitdir: ../.git/modules/submod" >expect &&
121 test_cmp expect submod/.git &&
124 git config core.worktree >actual &&
125 echo "../../../submod" >expect &&
126 test_cmp expect actual &&
132 rm -f heads head untracked &&
133 inspect addtest/submod ../.. &&
134 test_cmp expect heads &&
135 test_cmp expect head &&
136 test_cmp empty untracked
139 test_expect_success
'submodule add to .gitignored path fails' '
142 cat <<-\EOF >expect &&
143 The following path is ignored by one of your .gitignore files:
145 Use -f if you really want to add it.
147 # Does not use test_commit due to the ignore
148 echo "*" > .gitignore &&
149 git add --force .gitignore &&
150 git commit -m"Ignore everything" &&
151 ! git submodule add "$submodurl" submod >actual 2>&1 &&
152 test_i18ncmp expect actual
156 test_expect_success
'submodule add to .gitignored path with --force' '
159 git submodule add --force "$submodurl" submod
163 test_expect_success
'submodule add --branch' '
164 echo "refs/heads/initial" >expect-head &&
165 cat <<-\EOF >expect-heads &&
173 git submodule add -b initial "$submodurl" submod-branch &&
174 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
178 rm -f heads head untracked &&
179 inspect addtest/submod-branch ../.. &&
180 test_cmp expect-heads heads &&
181 test_cmp expect-head head &&
182 test_cmp empty untracked
185 test_expect_success
'submodule add with ./ in path' '
186 echo "refs/heads/master" >expect &&
191 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
195 rm -f heads head untracked &&
196 inspect addtest/dotsubmod/frotz ../../.. &&
197 test_cmp expect heads &&
198 test_cmp expect head &&
199 test_cmp empty untracked
202 test_expect_success
'submodule add with /././ in path' '
203 echo "refs/heads/master" >expect &&
208 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
212 rm -f heads head untracked &&
213 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
214 test_cmp expect heads &&
215 test_cmp expect head &&
216 test_cmp empty untracked
219 test_expect_success
'submodule add with // in path' '
220 echo "refs/heads/master" >expect &&
225 git submodule add "$submodurl" slashslashsubmod///frotz// &&
229 rm -f heads head untracked &&
230 inspect addtest/slashslashsubmod/frotz ../../.. &&
231 test_cmp expect heads &&
232 test_cmp expect head &&
233 test_cmp empty untracked
236 test_expect_success
'submodule add with /.. in path' '
237 echo "refs/heads/master" >expect &&
242 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
246 rm -f heads head untracked &&
247 inspect addtest/realsubmod ../.. &&
248 test_cmp expect heads &&
249 test_cmp expect head &&
250 test_cmp empty untracked
253 test_expect_success
'submodule add with ./, /.. and // in path' '
254 echo "refs/heads/master" >expect &&
259 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
263 rm -f heads head untracked &&
264 inspect addtest/realsubmod2 ../.. &&
265 test_cmp expect heads &&
266 test_cmp expect head &&
267 test_cmp empty untracked
270 test_expect_success
'submodule add in subdirectory' '
271 echo "refs/heads/master" >expect &&
277 git submodule add "$submodurl" ../realsubmod3 &&
281 rm -f heads head untracked &&
282 inspect addtest/realsubmod3 ../.. &&
283 test_cmp expect heads &&
284 test_cmp expect head &&
285 test_cmp empty untracked
288 test_expect_success
'submodule add in subdirectory with relative path should fail' '
291 test_must_fail git submodule add ../../ submod3 2>../../output.err
293 test_i18ngrep toplevel output.err
296 test_expect_success
'setup - add an example entry to .gitmodules' '
297 git config --file=.gitmodules submodule.example.url git://example.com/init.git
300 test_expect_success
'status should fail for unmapped paths' '
301 test_must_fail git submodule status
304 test_expect_success
'setup - map path in .gitmodules' '
305 cat <<\EOF >expect &&
306 [submodule "example"]
307 url = git://example.com/init.git
311 git config --file=.gitmodules submodule.example.path init &&
313 test_cmp expect .gitmodules
316 test_expect_success
'status should only print one line' '
317 git submodule status >lines &&
318 test_line_count = 1 lines
321 test_expect_success
'setup - fetch commit name from submodule' '
322 rev1=$(cd .subrepo && git rev-parse HEAD) &&
323 printf "rev1: %s\n" "$rev1" &&
327 test_expect_success
'status should initially be "missing"' '
328 git submodule status >lines &&
332 test_expect_success
'init should register submodule url in .git/config' '
333 echo git://example.com/init.git >expect &&
335 git submodule init &&
336 git config submodule.example.url >url &&
337 git config submodule.example.url ./.subrepo &&
342 test_failure_with_unknown_submodule
() {
343 test_must_fail git submodule
$1 no-such-submodule
2>output.err
&&
344 grep "^error: .*no-such-submodule" output.err
347 test_expect_success
'init should fail with unknown submodule' '
348 test_failure_with_unknown_submodule init
351 test_expect_success
'update should fail with unknown submodule' '
352 test_failure_with_unknown_submodule update
355 test_expect_success
'status should fail with unknown submodule' '
356 test_failure_with_unknown_submodule status
359 test_expect_success
'sync should fail with unknown submodule' '
360 test_failure_with_unknown_submodule sync
363 test_expect_success
'update should fail when path is used by a file' '
364 echo hello >expect &&
366 echo "hello" >init &&
367 test_must_fail git submodule update &&
372 test_expect_success
'update should fail when path is used by a nonempty directory' '
373 echo hello >expect &&
377 echo "hello" >init/a &&
379 test_must_fail git submodule update &&
381 test_cmp expect init/a
384 test_expect_success
'update should work when path is an empty dir' '
387 echo "$rev1" >expect &&
390 git submodule update -q >update.out &&
391 test_must_be_empty update.out &&
394 test_cmp expect head-sha1
397 test_expect_success
'status should be "up-to-date" after update' '
398 git submodule status >list &&
402 test_expect_success
'status "up-to-date" from subdirectory' '
406 git submodule status >../list
408 grep "^ $rev1" list &&
409 grep "\\.\\./init" list
412 test_expect_success
'status "up-to-date" from subdirectory with path' '
416 git submodule status ../init >../list
418 grep "^ $rev1" list &&
419 grep "\\.\\./init" list
422 test_expect_success
'status should be "modified" after submodule commit' '
427 git commit -m "submodule commit 2"
430 rev2=$(cd init && git rev-parse HEAD) &&
432 git submodule status >list &&
437 test_expect_success
'the --cached sha1 should be rev1' '
438 git submodule --cached status >list &&
442 test_expect_success
'git diff should report the SHA1 of the new submodule commit' '
444 grep "^+Subproject commit $rev2" diff
447 test_expect_success
'update should checkout rev1' '
449 echo "$rev1" >expect &&
451 git submodule update init &&
454 test_cmp expect head-sha1
457 test_expect_success
'status should be "up-to-date" after update' '
458 git submodule status >list &&
462 test_expect_success
'checkout superproject with subproject already present' '
463 git checkout initial &&
467 test_expect_success
'apply submodule diff' '
475 git commit -m "change subproject"
477 git update-index --add init &&
478 git commit -m "change init" &&
479 git format-patch -1 --stdout >P.diff &&
480 git checkout second &&
481 git apply --index P.diff &&
483 git diff --cached master >staged &&
484 test_cmp empty staged
487 test_expect_success
'update --init' '
489 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
490 git config --remove-section submodule.example &&
491 test_must_fail git config submodule.example.url &&
493 git submodule update init 2> update.out &&
495 test_i18ngrep "not initialized" update.out &&
496 test_must_fail git rev-parse --resolve-git-dir init/.git &&
498 git submodule update --init init &&
499 git rev-parse --resolve-git-dir init/.git
502 test_expect_success
'update --init from subdirectory' '
504 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
505 git config --remove-section submodule.example &&
506 test_must_fail git config submodule.example.url &&
511 git submodule update ../init 2>update.out &&
513 test_i18ngrep "not initialized" update.out &&
514 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
516 git submodule update --init ../init
518 git rev-parse --resolve-git-dir init/.git
521 test_expect_success
'do not add files from a submodule' '
524 test_must_fail git add init/a
528 test_expect_success
'gracefully add/reset submodule with a trailing slash' '
531 git commit -m "commit subproject" init &&
535 git diff --exit-code --cached init &&
537 git commit -m update a >/dev/null &&
538 git rev-parse HEAD) &&
540 test_must_fail git diff --exit-code --cached init &&
541 test $commit = $(git ls-files --stage |
542 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
544 git diff --exit-code --cached init
548 test_expect_success
'ls-files gracefully handles trailing slash' '
550 test "init" = "$(git ls-files init/)"
554 test_expect_success
'moving to a commit without submodule does not leave empty dir' '
558 git checkout initial &&
563 test_expect_success
'submodule <invalid-subcommand> fails' '
564 test_must_fail git submodule no-such-subcommand
567 test_expect_success
'add submodules without specifying an explicit path' '
574 git commit -m "repo commit 1"
576 git clone --bare repo/ bare.git &&
579 git submodule add "$submodurl/repo" &&
580 git config -f .gitmodules submodule.repo.path repo &&
581 git submodule add "$submodurl/bare.git" &&
582 git config -f .gitmodules submodule.bare.path bare
586 test_expect_success
'add should fail when path is used by a file' '
590 test_must_fail git submodule add "$submodurl/repo" file
594 test_expect_success
'add should fail when path is used by an existing directory' '
598 test_must_fail git submodule add "$submodurl/repo" empty-dir
602 test_expect_success
'use superproject as upstream when path is relative and no url is set there' '
605 git submodule add ../repo relative &&
606 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
607 git submodule sync relative &&
608 test "$(git config submodule.relative.url)" = "$submodurl/repo"
612 test_expect_success
'set up for relative path tests' '
624 git config -f .gitmodules submodule.sub.path sub &&
625 git config -f .gitmodules submodule.sub.url ../subrepo &&
626 cp .git/config pristine-.git-config &&
627 cp .gitmodules pristine-.gitmodules
631 test_expect_success
'../subrepo works with URL - ssh://hostname/repo' '
634 cp pristine-.git-config .git/config &&
635 cp pristine-.gitmodules .gitmodules &&
636 git config remote.origin.url ssh://hostname/repo &&
637 git submodule init &&
638 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
642 test_expect_success
'../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
645 cp pristine-.git-config .git/config &&
646 cp pristine-.gitmodules .gitmodules &&
647 git config remote.origin.url ssh://hostname:22/repo &&
648 git submodule init &&
649 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
653 # About the choice of the path in the next test:
654 # - double-slash side-steps path mangling issues on Windows
655 # - it is still an absolute local path
656 # - there cannot be a server with a blank in its name just in case the
657 # path is used erroneously to access a //server/share style path
658 test_expect_success
'../subrepo path works with local path - //somewhere else/repo' '
661 cp pristine-.git-config .git/config &&
662 cp pristine-.gitmodules .gitmodules &&
663 git config remote.origin.url "//somewhere else/repo" &&
664 git submodule init &&
665 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
669 test_expect_success
'../subrepo works with file URL - file:///tmp/repo' '
672 cp pristine-.git-config .git/config &&
673 cp pristine-.gitmodules .gitmodules &&
674 git config remote.origin.url file:///tmp/repo &&
675 git submodule init &&
676 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
680 test_expect_success
'../subrepo works with helper URL- helper:://hostname/repo' '
683 cp pristine-.git-config .git/config &&
684 cp pristine-.gitmodules .gitmodules &&
685 git config remote.origin.url helper:://hostname/repo &&
686 git submodule init &&
687 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
691 test_expect_success
'../subrepo works with scp-style URL - user@host:repo' '
694 cp pristine-.git-config .git/config &&
695 git config remote.origin.url user@host:repo &&
696 git submodule init &&
697 test "$(git config submodule.sub.url)" = user@host:subrepo
701 test_expect_success
'../subrepo works with scp-style URL - user@host:path/to/repo' '
704 cp pristine-.git-config .git/config &&
705 cp pristine-.gitmodules .gitmodules &&
706 git config remote.origin.url user@host:path/to/repo &&
707 git submodule init &&
708 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
712 test_expect_success
'../subrepo works with relative local path - foo' '
715 cp pristine-.git-config .git/config &&
716 cp pristine-.gitmodules .gitmodules &&
717 git config remote.origin.url foo &&
718 # actual: fails with an error
719 git submodule init &&
720 test "$(git config submodule.sub.url)" = subrepo
724 test_expect_success
'../subrepo works with relative local path - foo/bar' '
727 cp pristine-.git-config .git/config &&
728 cp pristine-.gitmodules .gitmodules &&
729 git config remote.origin.url foo/bar &&
730 git submodule init &&
731 test "$(git config submodule.sub.url)" = foo/subrepo
735 test_expect_success
'../subrepo works with relative local path - ./foo' '
738 cp pristine-.git-config .git/config &&
739 cp pristine-.gitmodules .gitmodules &&
740 git config remote.origin.url ./foo &&
741 git submodule init &&
742 test "$(git config submodule.sub.url)" = subrepo
746 test_expect_success
'../subrepo works with relative local path - ./foo/bar' '
749 cp pristine-.git-config .git/config &&
750 cp pristine-.gitmodules .gitmodules &&
751 git config remote.origin.url ./foo/bar &&
752 git submodule init &&
753 test "$(git config submodule.sub.url)" = foo/subrepo
757 test_expect_success
'../subrepo works with relative local path - ../foo' '
760 cp pristine-.git-config .git/config &&
761 cp pristine-.gitmodules .gitmodules &&
762 git config remote.origin.url ../foo &&
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
'../bar/a/b/c works with relative local path - ../foo/bar.git' '
782 cp pristine-.git-config .git/config &&
783 cp pristine-.gitmodules .gitmodules &&
785 (cd a/b/c; git init) &&
786 git config remote.origin.url ../foo/bar.git &&
787 git submodule add ../bar/a/b/c ./a/b/c &&
788 git submodule init &&
789 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
793 test_expect_success
'moving the superproject does not break submodules' '
796 git submodule status >expect
798 mv addtest addtest2 &&
801 git submodule status >actual &&
802 test_cmp expect actual
806 test_expect_success
'submodule add --name allows to replace a submodule with another at the same path' '
811 echo "$submodurl/repo" >expect &&
812 git config remote.origin.url >actual &&
813 test_cmp expect actual &&
814 echo "gitdir: ../.git/modules/repo" >expect &&
819 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
820 test_must_be_empty actual &&
821 echo "gitdir: ../.git/modules/submod" >expect &&
822 test_cmp expect submod/.git &&
825 echo "$submodurl/bare.git" >expect &&
826 git config remote.origin.url >actual &&
827 test_cmp expect actual &&
828 echo "gitdir: ../.git/modules/repo_new" >expect &&
831 echo "repo" >expect &&
832 test_must_fail git config -f .gitmodules submodule.repo.path &&
833 git config -f .gitmodules submodule.repo_new.path >actual &&
834 test_cmp expect actual&&
835 echo "$submodurl/repo" >expect &&
836 test_must_fail git config -f .gitmodules submodule.repo.url &&
837 echo "$submodurl/bare.git" >expect &&
838 git config -f .gitmodules submodule.repo_new.url >actual &&
839 test_cmp expect actual &&
840 echo "$submodurl/repo" >expect &&
841 git config submodule.repo.url >actual &&
842 test_cmp expect actual &&
843 echo "$submodurl/bare.git" >expect &&
844 git config submodule.repo_new.url >actual &&
845 test_cmp expect actual
849 test_expect_success
'recursive relative submodules stay relative' '
850 test_when_finished "rm -rf super clone2 subsub sub3" &&
857 git commit -m "initial commit"
865 git commit -m "initial commit" &&
866 git submodule add ../subsub dirdir/subsub &&
867 git commit -m "add submodule subsub"
875 git commit -m "initial commit" &&
876 git submodule add ../sub3 &&
877 git commit -m "add submodule sub"
879 git clone super clone2 &&
882 git submodule update --init --recursive &&
883 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
884 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
886 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
887 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
890 test_expect_success
'submodule add with an existing name fails unless forced' '
895 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
897 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
898 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
899 echo "$submodurl/bare.git" >expect &&
900 git config submodule.repo_new.url >actual &&
901 test_cmp expect actual &&
902 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
904 echo "repo" >expect &&
905 git config -f .gitmodules submodule.repo_new.path >actual &&
906 test_cmp expect actual&&
907 echo "$submodurl/repo.git" >expect &&
908 git config -f .gitmodules submodule.repo_new.url >actual &&
909 test_cmp expect actual &&
910 echo "$submodurl/repo.git" >expect &&
911 git config submodule.repo_new.url >actual &&
912 test_cmp expect actual
916 test_expect_success
'set up a second submodule' '
917 git submodule add ./init2 example2 &&
918 git commit -m "submodule example2 added"
921 test_expect_success
'submodule deinit works on repository without submodules' '
922 test_when_finished "rm -rf newdirectory" &&
923 mkdir newdirectory &&
929 git commit -m "repo should not be empty" &&
930 git submodule deinit . &&
931 git submodule deinit --all
935 test_expect_success
'submodule deinit should remove the whole submodule section from .git/config' '
936 git config submodule.example.foo bar &&
937 git config submodule.example2.frotz nitfol &&
938 git submodule deinit init &&
939 test -z "$(git config --get-regexp "submodule\.example\.")" &&
940 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
941 test -f example2/.git &&
945 test_expect_success
'submodule deinit from subdirectory' '
946 git submodule update --init &&
947 git config submodule.example.foo bar &&
951 git submodule deinit ../init >../output
953 grep "\\.\\./init" output &&
954 test -z "$(git config --get-regexp "submodule\.example\.")" &&
955 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
956 test -f example2/.git &&
960 test_expect_success
'submodule deinit . deinits all initialized submodules' '
961 git submodule update --init &&
962 git config submodule.example.foo bar &&
963 git config submodule.example2.frotz nitfol &&
964 test_must_fail git submodule deinit &&
965 git submodule deinit . >actual &&
966 test -z "$(git config --get-regexp "submodule\.example\.")" &&
967 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
968 test_i18ngrep "Cleared directory .init" actual &&
969 test_i18ngrep "Cleared directory .example2" actual &&
973 test_expect_success
'submodule deinit --all deinits all initialized submodules' '
974 git submodule update --init &&
975 git config submodule.example.foo bar &&
976 git config submodule.example2.frotz nitfol &&
977 test_must_fail git submodule deinit &&
978 git submodule deinit --all >actual &&
979 test -z "$(git config --get-regexp "submodule\.example\.")" &&
980 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
981 test_i18ngrep "Cleared directory .init" actual &&
982 test_i18ngrep "Cleared directory .example2" actual &&
986 test_expect_success
'submodule deinit deinits a submodule when its work tree is missing or empty' '
987 git submodule update --init &&
988 rm -rf init example2/* example2/.git &&
989 git submodule deinit init example2 >actual &&
990 test -z "$(git config --get-regexp "submodule\.example\.")" &&
991 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
992 test_i18ngrep ! "Cleared directory .init" actual &&
993 test_i18ngrep "Cleared directory .example2" actual &&
997 test_expect_success
'submodule deinit fails when the submodule contains modifications unless forced' '
998 git submodule update --init &&
1000 test_must_fail git submodule deinit init &&
1001 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1002 test -f example2/.git &&
1003 git submodule deinit -f init >actual &&
1004 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1005 test_i18ngrep "Cleared directory .init" actual &&
1009 test_expect_success
'submodule deinit fails when the submodule contains untracked files unless forced' '
1010 git submodule update --init &&
1011 echo X >>init/untracked &&
1012 test_must_fail git submodule deinit init &&
1013 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1014 test -f example2/.git &&
1015 git submodule deinit -f init >actual &&
1016 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1017 test_i18ngrep "Cleared directory .init" actual &&
1021 test_expect_success
'submodule deinit fails when the submodule HEAD does not match unless forced' '
1022 git submodule update --init &&
1027 test_must_fail git submodule deinit init &&
1028 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1029 test -f example2/.git &&
1030 git submodule deinit -f init >actual &&
1031 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1032 test_i18ngrep "Cleared directory .init" actual &&
1036 test_expect_success
'submodule deinit is silent when used on an uninitialized submodule' '
1037 git submodule update --init &&
1038 git submodule deinit init >actual &&
1039 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1040 test_i18ngrep "Cleared directory .init" actual &&
1041 git submodule deinit init >actual &&
1042 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1043 test_i18ngrep "Cleared directory .init" actual &&
1044 git submodule deinit . >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 &&
1048 git submodule deinit . >actual &&
1049 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1050 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1051 test_i18ngrep "Cleared directory .init" actual &&
1052 git submodule deinit --all >actual &&
1053 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1054 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1055 test_i18ngrep "Cleared directory .init" actual &&
1059 test_expect_success
'submodule deinit fails when submodule has a .git directory even when forced' '
1060 git submodule update --init &&
1064 cp -R ../.git/modules/example .git &&
1065 GIT_WORK_TREE=. git config --unset core.worktree
1067 test_must_fail git submodule deinit init &&
1068 test_must_fail git submodule deinit -f init &&
1069 test -d init/.git &&
1070 test -n "$(git config --get-regexp "submodule\.example\.")"
1073 test_expect_success
'submodule with UTF-8 name' '
1074 svname=$(printf "\303\245 \303\244\303\266") &&
1081 git commit -m "init sub"
1083 git submodule add ./"$svname" &&
1084 git submodule >&2 &&
1085 test -n "$(git submodule | grep "$svname")"
1088 test_expect_success
'submodule add clone shallow submodule' '
1094 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1097 test 1 = $(git log --oneline | wc -l)
1102 test_expect_success
'submodule helper list is not confused by common prefixes' '
1107 echo hi >testfile2 &&
1109 git commit -m "test1"
1115 echo hello >testfile1 &&
1117 git commit -m "test2"
1119 git submodule add /dir1/b dir1/b &&
1120 git submodule add /dir2/b dir2/b &&
1121 git commit -m "first submodule commit" &&
1122 git submodule--helper list dir1/b |cut -c51- >actual &&
1123 echo "dir1/b" >expect &&
1124 test_cmp expect actual