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
'setup - repository in init subdirectory' '
56 git commit -m "submodule commit 1" &&
57 git tag -a -m "rev-1" rev-1
61 test_expect_success
'setup - commit with gitlink' '
65 git commit -m "super commit 1"
68 test_expect_success
'setup - hide init subdirectory' '
72 test_expect_success
'setup - repository to add submodules to' '
74 git init addtest-ignore
77 # The 'submodule add' tests need some repository to add as a submodule.
78 # The trash directory is a good one as any. We need to canonicalize
79 # the name, though, as some tests compare it to the absolute path git
80 # generates, which will expand symbolic links.
84 git for-each-ref
--format='%(refname)' 'refs/heads/*'
93 listbranches
>"$dotdot/heads" &&
94 { git symbolic-ref HEAD ||
:; } >"$dotdot/head" &&
95 git rev-parse HEAD
>"$dotdot/head-sha1" &&
96 git update-index
--refresh &&
97 git diff-files
--exit-code &&
98 git clean
-n -d -x >"$dotdot/untracked"
102 test_expect_success
'submodule add' '
103 echo "refs/heads/master" >expect &&
107 git submodule add -q "$submodurl" submod >actual &&
108 test_must_be_empty actual &&
109 echo "gitdir: ../.git/modules/submod" >expect &&
110 test_cmp expect submod/.git &&
113 git config core.worktree >actual &&
114 echo "../../../submod" >expect &&
115 test_cmp expect actual &&
121 rm -f heads head untracked &&
122 inspect addtest/submod ../.. &&
123 test_cmp expect heads &&
124 test_cmp expect head &&
125 test_must_be_empty untracked
128 test_expect_success
'setup parent and one repository' '
129 test_create_repo parent &&
130 test_commit -C parent one
133 test_expect_success
'redirected submodule add does not show progress' '
134 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
137 test_i18ngrep ! "Checking connectivity" err
140 test_expect_success
'redirected submodule add --progress does show progress' '
141 git -C addtest submodule add --progress "file://$submodurl/parent" \
142 submod-redirected-progress 2>err && \
146 test_expect_success
'submodule add to .gitignored path fails' '
149 cat <<-\EOF >expect &&
150 The following path is ignored by one of your .gitignore files:
152 Use -f if you really want to add it.
154 # Does not use test_commit due to the ignore
155 echo "*" > .gitignore &&
156 git add --force .gitignore &&
157 git commit -m"Ignore everything" &&
158 ! git submodule add "$submodurl" submod >actual 2>&1 &&
159 test_i18ncmp expect actual
163 test_expect_success
'submodule add to .gitignored path with --force' '
166 git submodule add --force "$submodurl" submod
170 test_expect_success
'submodule add to reconfigure existing submodule with --force' '
173 bogus_url="$(pwd)/bogus-url" &&
174 git submodule add --force "$bogus_url" submod &&
175 git submodule add --force -b initial "$submodurl" submod-branch &&
176 test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" &&
177 test "$bogus_url" = "$(git config submodule.submod.url)" &&
179 git submodule add --force "$submodurl" submod &&
180 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
181 test "$submodurl" = "$(git config submodule.submod.url)"
185 test_expect_success
'submodule add --branch' '
186 echo "refs/heads/initial" >expect-head &&
187 cat <<-\EOF >expect-heads &&
194 git submodule add -b initial "$submodurl" submod-branch &&
195 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
199 rm -f heads head untracked &&
200 inspect addtest/submod-branch ../.. &&
201 test_cmp expect-heads heads &&
202 test_cmp expect-head head &&
203 test_must_be_empty untracked
206 test_expect_success
'submodule add with ./ in path' '
207 echo "refs/heads/master" >expect &&
211 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
215 rm -f heads head untracked &&
216 inspect addtest/dotsubmod/frotz ../../.. &&
217 test_cmp expect heads &&
218 test_cmp expect head &&
219 test_must_be_empty untracked
222 test_expect_success
'submodule add with /././ in path' '
223 echo "refs/heads/master" >expect &&
227 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
231 rm -f heads head untracked &&
232 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
233 test_cmp expect heads &&
234 test_cmp expect head &&
235 test_must_be_empty untracked
238 test_expect_success
'submodule add with // in path' '
239 echo "refs/heads/master" >expect &&
243 git submodule add "$submodurl" slashslashsubmod///frotz// &&
247 rm -f heads head untracked &&
248 inspect addtest/slashslashsubmod/frotz ../../.. &&
249 test_cmp expect heads &&
250 test_cmp expect head &&
251 test_must_be_empty untracked
254 test_expect_success
'submodule add with /.. in path' '
255 echo "refs/heads/master" >expect &&
259 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
263 rm -f heads head untracked &&
264 inspect addtest/realsubmod ../.. &&
265 test_cmp expect heads &&
266 test_cmp expect head &&
267 test_must_be_empty untracked
270 test_expect_success
'submodule add with ./, /.. and // in path' '
271 echo "refs/heads/master" >expect &&
275 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
279 rm -f heads head untracked &&
280 inspect addtest/realsubmod2 ../.. &&
281 test_cmp expect heads &&
282 test_cmp expect head &&
283 test_must_be_empty untracked
286 test_expect_success
!CYGWIN
'submodule add with \\ in path' '
287 test_when_finished "rm -rf parent sub\\with\\backslash" &&
289 # Initialize a repo with a backslash in its name
290 git init sub\\with\\backslash &&
291 touch sub\\with\\backslash/empty.file &&
292 git -C sub\\with\\backslash add empty.file &&
293 git -C sub\\with\\backslash commit -m "Added empty.file" &&
295 # Add that repository as a submodule
297 git -C parent submodule add ../sub\\with\\backslash
300 test_expect_success
'submodule add in subdirectory' '
301 echo "refs/heads/master" >expect &&
306 git submodule add "$submodurl" ../realsubmod3 &&
310 rm -f heads head untracked &&
311 inspect addtest/realsubmod3 ../.. &&
312 test_cmp expect heads &&
313 test_cmp expect head &&
314 test_must_be_empty untracked
317 test_expect_success
'submodule add in subdirectory with relative path should fail' '
320 test_must_fail git submodule add ../../ submod3 2>../../output.err
322 test_i18ngrep toplevel output.err
325 test_expect_success
'setup - add an example entry to .gitmodules' '
326 git config --file=.gitmodules submodule.example.url git://example.com/init.git
329 test_expect_success
'status should fail for unmapped paths' '
330 test_must_fail git submodule status
333 test_expect_success
'setup - map path in .gitmodules' '
334 cat <<\EOF >expect &&
335 [submodule "example"]
336 url = git://example.com/init.git
340 git config --file=.gitmodules submodule.example.path init &&
342 test_cmp expect .gitmodules
345 test_expect_success
'status should only print one line' '
346 git submodule status >lines &&
347 test_line_count = 1 lines
350 test_expect_success
'setup - fetch commit name from submodule' '
351 rev1=$(cd .subrepo && git rev-parse HEAD) &&
352 printf "rev1: %s\n" "$rev1" &&
356 test_expect_success
'status should initially be "missing"' '
357 git submodule status >lines &&
361 test_expect_success
'init should register submodule url in .git/config' '
362 echo git://example.com/init.git >expect &&
364 git submodule init &&
365 git config submodule.example.url >url &&
366 git config submodule.example.url ./.subrepo &&
371 test_failure_with_unknown_submodule
() {
372 test_must_fail git submodule
$1 no-such-submodule
2>output.err
&&
373 test_i18ngrep
"^error: .*no-such-submodule" output.err
376 test_expect_success
'init should fail with unknown submodule' '
377 test_failure_with_unknown_submodule init
380 test_expect_success
'update should fail with unknown submodule' '
381 test_failure_with_unknown_submodule update
384 test_expect_success
'status should fail with unknown submodule' '
385 test_failure_with_unknown_submodule status
388 test_expect_success
'sync should fail with unknown submodule' '
389 test_failure_with_unknown_submodule sync
392 test_expect_success
'update should fail when path is used by a file' '
393 echo hello >expect &&
395 echo "hello" >init &&
396 test_must_fail git submodule update &&
401 test_expect_success
'update should fail when path is used by a nonempty directory' '
402 echo hello >expect &&
406 echo "hello" >init/a &&
408 test_must_fail git submodule update &&
410 test_cmp expect init/a
413 test_expect_success
'update should work when path is an empty dir' '
416 echo "$rev1" >expect &&
419 git submodule update -q >update.out &&
420 test_must_be_empty update.out &&
423 test_cmp expect head-sha1
426 test_expect_success
'status should be "up-to-date" after update' '
427 git submodule status >list &&
431 test_expect_success
'status "up-to-date" from subdirectory' '
435 git submodule status >../list
437 grep "^ $rev1" list &&
438 grep "\\.\\./init" list
441 test_expect_success
'status "up-to-date" from subdirectory with path' '
445 git submodule status ../init >../list
447 grep "^ $rev1" list &&
448 grep "\\.\\./init" list
451 test_expect_success
'status should be "modified" after submodule commit' '
456 git commit -m "submodule commit 2"
459 rev2=$(cd init && git rev-parse HEAD) &&
461 git submodule status >list &&
466 test_expect_success
'the --cached sha1 should be rev1' '
467 git submodule --cached status >list &&
471 test_expect_success
'git diff should report the SHA1 of the new submodule commit' '
473 grep "^+Subproject commit $rev2" diff
476 test_expect_success
'update should checkout rev1' '
478 echo "$rev1" >expect &&
480 git submodule update init &&
483 test_cmp expect head-sha1
486 test_expect_success
'status should be "up-to-date" after update' '
487 git submodule status >list &&
491 test_expect_success
'checkout superproject with subproject already present' '
492 git checkout initial &&
496 test_expect_success
'apply submodule diff' '
502 git commit -m "change subproject"
504 git update-index --add init &&
505 git commit -m "change init" &&
506 git format-patch -1 --stdout >P.diff &&
507 git checkout second &&
508 git apply --index P.diff &&
510 git diff --cached master >staged &&
511 test_must_be_empty staged
514 test_expect_success
'update --init' '
516 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
517 git config --remove-section submodule.example &&
518 test_must_fail git config submodule.example.url &&
520 git submodule update init 2> update.out &&
522 test_i18ngrep "not initialized" update.out &&
523 test_must_fail git rev-parse --resolve-git-dir init/.git &&
525 git submodule update --init init &&
526 git rev-parse --resolve-git-dir init/.git
529 test_expect_success
'update --init from subdirectory' '
531 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
532 git config --remove-section submodule.example &&
533 test_must_fail git config submodule.example.url &&
538 git submodule update ../init 2>update.out &&
540 test_i18ngrep "not initialized" update.out &&
541 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
543 git submodule update --init ../init
545 git rev-parse --resolve-git-dir init/.git
548 test_expect_success
'do not add files from a submodule' '
551 test_must_fail git add init/a
555 test_expect_success
'gracefully add/reset submodule with a trailing slash' '
558 git commit -m "commit subproject" init &&
562 git diff --exit-code --cached init &&
564 git commit -m update a >/dev/null &&
565 git rev-parse HEAD) &&
567 test_must_fail git diff --exit-code --cached init &&
568 test $commit = $(git ls-files --stage |
569 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
571 git diff --exit-code --cached init
575 test_expect_success
'ls-files gracefully handles trailing slash' '
577 test "init" = "$(git ls-files init/)"
581 test_expect_success
'moving to a commit without submodule does not leave empty dir' '
585 git checkout initial &&
590 test_expect_success
'submodule <invalid-subcommand> fails' '
591 test_must_fail git submodule no-such-subcommand
594 test_expect_success
'add submodules without specifying an explicit path' '
601 git commit -m "repo commit 1"
603 git clone --bare repo/ bare.git &&
606 git submodule add "$submodurl/repo" &&
607 git config -f .gitmodules submodule.repo.path repo &&
608 git submodule add "$submodurl/bare.git" &&
609 git config -f .gitmodules submodule.bare.path bare
613 test_expect_success
'add should fail when path is used by a file' '
617 test_must_fail git submodule add "$submodurl/repo" file
621 test_expect_success
'add should fail when path is used by an existing directory' '
625 test_must_fail git submodule add "$submodurl/repo" empty-dir
629 test_expect_success
'use superproject as upstream when path is relative and no url is set there' '
632 git submodule add ../repo relative &&
633 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
634 git submodule sync relative &&
635 test "$(git config submodule.relative.url)" = "$submodurl/repo"
639 test_expect_success
'set up for relative path tests' '
651 git config -f .gitmodules submodule.sub.path sub &&
652 git config -f .gitmodules submodule.sub.url ../subrepo &&
653 cp .git/config pristine-.git-config &&
654 cp .gitmodules pristine-.gitmodules
658 test_expect_success
'../subrepo works with URL - ssh://hostname/repo' '
661 cp pristine-.git-config .git/config &&
662 cp pristine-.gitmodules .gitmodules &&
663 git config remote.origin.url ssh://hostname/repo &&
664 git submodule init &&
665 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
669 test_expect_success
'../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
672 cp pristine-.git-config .git/config &&
673 cp pristine-.gitmodules .gitmodules &&
674 git config remote.origin.url ssh://hostname:22/repo &&
675 git submodule init &&
676 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
680 # About the choice of the path in the next test:
681 # - double-slash side-steps path mangling issues on Windows
682 # - it is still an absolute local path
683 # - there cannot be a server with a blank in its name just in case the
684 # path is used erroneously to access a //server/share style path
685 test_expect_success
'../subrepo path works with local path - //somewhere else/repo' '
688 cp pristine-.git-config .git/config &&
689 cp pristine-.gitmodules .gitmodules &&
690 git config remote.origin.url "//somewhere else/repo" &&
691 git submodule init &&
692 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
696 test_expect_success
'../subrepo works with file URL - file:///tmp/repo' '
699 cp pristine-.git-config .git/config &&
700 cp pristine-.gitmodules .gitmodules &&
701 git config remote.origin.url file:///tmp/repo &&
702 git submodule init &&
703 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
707 test_expect_success
'../subrepo works with helper URL- helper:://hostname/repo' '
710 cp pristine-.git-config .git/config &&
711 cp pristine-.gitmodules .gitmodules &&
712 git config remote.origin.url helper:://hostname/repo &&
713 git submodule init &&
714 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
718 test_expect_success
'../subrepo works with scp-style URL - user@host:repo' '
721 cp pristine-.git-config .git/config &&
722 git config remote.origin.url user@host:repo &&
723 git submodule init &&
724 test "$(git config submodule.sub.url)" = user@host:subrepo
728 test_expect_success
'../subrepo works with scp-style URL - user@host:path/to/repo' '
731 cp pristine-.git-config .git/config &&
732 cp pristine-.gitmodules .gitmodules &&
733 git config remote.origin.url user@host:path/to/repo &&
734 git submodule init &&
735 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
739 test_expect_success
'../subrepo works with relative local path - foo' '
742 cp pristine-.git-config .git/config &&
743 cp pristine-.gitmodules .gitmodules &&
744 git config remote.origin.url foo &&
745 # actual: fails with an error
746 git submodule init &&
747 test "$(git config submodule.sub.url)" = subrepo
751 test_expect_success
'../subrepo works with relative local path - foo/bar' '
754 cp pristine-.git-config .git/config &&
755 cp pristine-.gitmodules .gitmodules &&
756 git config remote.origin.url foo/bar &&
757 git submodule init &&
758 test "$(git config submodule.sub.url)" = foo/subrepo
762 test_expect_success
'../subrepo works with relative local path - ./foo' '
765 cp pristine-.git-config .git/config &&
766 cp pristine-.gitmodules .gitmodules &&
767 git config remote.origin.url ./foo &&
768 git submodule init &&
769 test "$(git config submodule.sub.url)" = subrepo
773 test_expect_success
'../subrepo works with relative local path - ./foo/bar' '
776 cp pristine-.git-config .git/config &&
777 cp pristine-.gitmodules .gitmodules &&
778 git config remote.origin.url ./foo/bar &&
779 git submodule init &&
780 test "$(git config submodule.sub.url)" = foo/subrepo
784 test_expect_success
'../subrepo works with relative local path - ../foo' '
787 cp pristine-.git-config .git/config &&
788 cp pristine-.gitmodules .gitmodules &&
789 git config remote.origin.url ../foo &&
790 git submodule init &&
791 test "$(git config submodule.sub.url)" = ../subrepo
795 test_expect_success
'../subrepo works with relative local path - ../foo/bar' '
798 cp pristine-.git-config .git/config &&
799 cp pristine-.gitmodules .gitmodules &&
800 git config remote.origin.url ../foo/bar &&
801 git submodule init &&
802 test "$(git config submodule.sub.url)" = ../foo/subrepo
806 test_expect_success
'../bar/a/b/c works with relative local path - ../foo/bar.git' '
809 cp pristine-.git-config .git/config &&
810 cp pristine-.gitmodules .gitmodules &&
812 (cd a/b/c && git init) &&
813 git config remote.origin.url ../foo/bar.git &&
814 git submodule add ../bar/a/b/c ./a/b/c &&
815 git submodule init &&
816 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
820 test_expect_success
'moving the superproject does not break submodules' '
823 git submodule status >expect
825 mv addtest addtest2 &&
828 git submodule status >actual &&
829 test_cmp expect actual
833 test_expect_success
'moving the submodule does not break the superproject' '
838 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
839 mv addtest2/repo addtest2/repo.bak &&
840 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
845 test_cmp expect actual
848 test_expect_success
'submodule add --name allows to replace a submodule with another at the same path' '
853 echo "$submodurl/repo" >expect &&
854 git config remote.origin.url >actual &&
855 test_cmp expect actual &&
856 echo "gitdir: ../.git/modules/repo" >expect &&
861 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
862 test_must_be_empty actual &&
863 echo "gitdir: ../.git/modules/submod" >expect &&
864 test_cmp expect submod/.git &&
867 echo "$submodurl/bare.git" >expect &&
868 git config remote.origin.url >actual &&
869 test_cmp expect actual &&
870 echo "gitdir: ../.git/modules/repo_new" >expect &&
873 echo "repo" >expect &&
874 test_must_fail git config -f .gitmodules submodule.repo.path &&
875 git config -f .gitmodules submodule.repo_new.path >actual &&
876 test_cmp expect actual&&
877 echo "$submodurl/repo" >expect &&
878 test_must_fail git config -f .gitmodules submodule.repo.url &&
879 echo "$submodurl/bare.git" >expect &&
880 git config -f .gitmodules submodule.repo_new.url >actual &&
881 test_cmp expect actual &&
882 echo "$submodurl/repo" >expect &&
883 git config submodule.repo.url >actual &&
884 test_cmp expect actual &&
885 echo "$submodurl/bare.git" >expect &&
886 git config submodule.repo_new.url >actual &&
887 test_cmp expect actual
891 test_expect_success
'recursive relative submodules stay relative' '
892 test_when_finished "rm -rf super clone2 subsub sub3" &&
899 git commit -m "initial commit"
907 git commit -m "initial commit" &&
908 git submodule add ../subsub dirdir/subsub &&
909 git commit -m "add submodule subsub"
917 git commit -m "initial commit" &&
918 git submodule add ../sub3 &&
919 git commit -m "add submodule sub"
921 git clone super clone2 &&
924 git submodule update --init --recursive &&
925 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
926 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
928 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
929 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
932 test_expect_success
'submodule add with an existing name fails unless forced' '
937 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
939 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
940 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
941 echo "$submodurl/bare.git" >expect &&
942 git config submodule.repo_new.url >actual &&
943 test_cmp expect actual &&
944 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
946 echo "repo" >expect &&
947 git config -f .gitmodules submodule.repo_new.path >actual &&
948 test_cmp expect actual&&
949 echo "$submodurl/repo.git" >expect &&
950 git config -f .gitmodules submodule.repo_new.url >actual &&
951 test_cmp expect actual &&
952 echo "$submodurl/repo.git" >expect &&
953 git config submodule.repo_new.url >actual &&
954 test_cmp expect actual
958 test_expect_success
'set up a second submodule' '
959 git submodule add ./init2 example2 &&
960 git commit -m "submodule example2 added"
963 test_expect_success
'submodule deinit works on repository without submodules' '
964 test_when_finished "rm -rf newdirectory" &&
965 mkdir newdirectory &&
971 git commit -m "repo should not be empty" &&
972 git submodule deinit . &&
973 git submodule deinit --all
977 test_expect_success
'submodule deinit should remove the whole submodule section from .git/config' '
978 git config submodule.example.foo bar &&
979 git config submodule.example2.frotz nitfol &&
980 git submodule deinit init &&
981 test -z "$(git config --get-regexp "submodule\.example\.")" &&
982 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
983 test -f example2/.git &&
987 test_expect_success
'submodule deinit should unset core.worktree' '
988 test_path_is_file .git/modules/example/config &&
989 test_must_fail git config -f .git/modules/example/config core.worktree
992 test_expect_success
'submodule deinit from subdirectory' '
993 git submodule update --init &&
994 git config submodule.example.foo bar &&
998 git submodule deinit ../init >../output
1000 test_i18ngrep "\\.\\./init" output &&
1001 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1002 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1003 test -f example2/.git &&
1007 test_expect_success
'submodule deinit . deinits all initialized submodules' '
1008 git submodule update --init &&
1009 git config submodule.example.foo bar &&
1010 git config submodule.example2.frotz nitfol &&
1011 test_must_fail git submodule deinit &&
1012 git submodule deinit . >actual &&
1013 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1014 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1015 test_i18ngrep "Cleared directory .init" actual &&
1016 test_i18ngrep "Cleared directory .example2" actual &&
1020 test_expect_success
'submodule deinit --all deinits all initialized submodules' '
1021 git submodule update --init &&
1022 git config submodule.example.foo bar &&
1023 git config submodule.example2.frotz nitfol &&
1024 test_must_fail git submodule deinit &&
1025 git submodule deinit --all >actual &&
1026 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1027 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1028 test_i18ngrep "Cleared directory .init" actual &&
1029 test_i18ngrep "Cleared directory .example2" actual &&
1033 test_expect_success
'submodule deinit deinits a submodule when its work tree is missing or empty' '
1034 git submodule update --init &&
1035 rm -rf init example2/* example2/.git &&
1036 git submodule deinit init example2 >actual &&
1037 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1038 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1039 test_i18ngrep ! "Cleared directory .init" actual &&
1040 test_i18ngrep "Cleared directory .example2" actual &&
1044 test_expect_success
'submodule deinit fails when the submodule contains modifications unless forced' '
1045 git submodule update --init &&
1047 test_must_fail git submodule deinit init &&
1048 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1049 test -f example2/.git &&
1050 git submodule deinit -f init >actual &&
1051 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1052 test_i18ngrep "Cleared directory .init" actual &&
1056 test_expect_success
'submodule deinit fails when the submodule contains untracked files unless forced' '
1057 git submodule update --init &&
1058 echo X >>init/untracked &&
1059 test_must_fail git submodule deinit init &&
1060 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1061 test -f example2/.git &&
1062 git submodule deinit -f init >actual &&
1063 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1064 test_i18ngrep "Cleared directory .init" actual &&
1068 test_expect_success
'submodule deinit fails when the submodule HEAD does not match unless forced' '
1069 git submodule update --init &&
1074 test_must_fail git submodule deinit init &&
1075 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1076 test -f example2/.git &&
1077 git submodule deinit -f init >actual &&
1078 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1079 test_i18ngrep "Cleared directory .init" actual &&
1083 test_expect_success
'submodule deinit is silent when used on an uninitialized submodule' '
1084 git submodule update --init &&
1085 git submodule deinit init >actual &&
1086 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1087 test_i18ngrep "Cleared directory .init" actual &&
1088 git submodule deinit init >actual &&
1089 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1090 test_i18ngrep "Cleared directory .init" actual &&
1091 git submodule deinit . >actual &&
1092 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1093 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1094 test_i18ngrep "Cleared directory .init" actual &&
1095 git submodule deinit . >actual &&
1096 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1097 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1098 test_i18ngrep "Cleared directory .init" actual &&
1099 git submodule deinit --all >actual &&
1100 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1101 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1102 test_i18ngrep "Cleared directory .init" actual &&
1106 test_expect_success
'submodule deinit fails when submodule has a .git directory even when forced' '
1107 git submodule update --init &&
1111 cp -R ../.git/modules/example .git &&
1112 GIT_WORK_TREE=. git config --unset core.worktree
1114 test_must_fail git submodule deinit init &&
1115 test_must_fail git submodule deinit -f init &&
1116 test -d init/.git &&
1117 test -n "$(git config --get-regexp "submodule\.example\.")"
1120 test_expect_success
'submodule with UTF-8 name' '
1121 svname=$(printf "\303\245 \303\244\303\266") &&
1128 git commit -m "init sub"
1130 git submodule add ./"$svname" &&
1131 git submodule >&2 &&
1132 test -n "$(git submodule | grep "$svname")"
1135 test_expect_success
'submodule add clone shallow submodule' '
1141 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1144 test 1 = $(git log --oneline | wc -l)
1149 test_expect_success
'submodule helper list is not confused by common prefixes' '
1154 echo hi >testfile2 &&
1156 git commit -m "test1"
1162 echo hello >testfile1 &&
1164 git commit -m "test2"
1166 git submodule add /dir1/b dir1/b &&
1167 git submodule add /dir2/b dir2/b &&
1168 git commit -m "first submodule commit" &&
1169 git submodule--helper list dir1/b |cut -c51- >actual &&
1170 echo "dir1/b" >expect &&
1171 test_cmp expect actual
1174 test_expect_success
'setup superproject with submodules' '
1176 test_commit -C sub1 test &&
1177 test_commit -C sub1 test2 &&
1178 git init multisuper &&
1179 git -C multisuper submodule add ../sub1 sub0 &&
1180 git -C multisuper submodule add ../sub1 sub1 &&
1181 git -C multisuper submodule add ../sub1 sub2 &&
1182 git -C multisuper submodule add ../sub1 sub3 &&
1183 git -C multisuper commit -m "add some submodules"
1193 test_expect_success
'submodule update --init with a specification' '
1194 test_when_finished "rm -rf multisuper_clone" &&
1196 git clone file://"$pwd"/multisuper multisuper_clone &&
1197 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1198 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1199 test_cmp expect actual
1202 test_expect_success
'submodule update --init with submodule.active set' '
1203 test_when_finished "rm -rf multisuper_clone" &&
1205 git clone file://"$pwd"/multisuper multisuper_clone &&
1206 git -C multisuper_clone config submodule.active "." &&
1207 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1208 git -C multisuper_clone submodule update --init &&
1209 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1210 test_cmp expect actual
1213 test_expect_success
'submodule update and setting submodule.<name>.active' '
1214 test_when_finished "rm -rf multisuper_clone" &&
1216 git clone file://"$pwd"/multisuper multisuper_clone &&
1217 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1218 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1219 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1221 cat >expect <<-\EOF &&
1227 git -C multisuper_clone submodule update &&
1228 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1229 test_cmp expect actual
1232 test_expect_success
'clone --recurse-submodules with a pathspec works' '
1233 test_when_finished "rm -rf multisuper_clone" &&
1234 cat >expected <<-\EOF &&
1241 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1242 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1243 test_cmp expected actual
1246 test_expect_success
'clone with multiple --recurse-submodules options' '
1247 test_when_finished "rm -rf multisuper_clone" &&
1248 cat >expect <<-\EOF &&
1255 git clone --recurse-submodules="." \
1256 --recurse-submodules=":(exclude)sub0" \
1257 --recurse-submodules=":(exclude)sub2" \
1258 multisuper multisuper_clone &&
1259 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1260 test_cmp expect actual
1263 test_expect_success
'clone and subsequent updates correctly auto-initialize submodules' '
1264 test_when_finished "rm -rf multisuper_clone" &&
1265 cat <<-\EOF >expect &&
1272 cat <<-\EOF >expect2 &&
1281 git clone --recurse-submodules="." \
1282 --recurse-submodules=":(exclude)sub0" \
1283 --recurse-submodules=":(exclude)sub2" \
1284 --recurse-submodules=":(exclude)sub4" \
1285 multisuper multisuper_clone &&
1287 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1288 test_cmp expect actual &&
1290 git -C multisuper submodule add ../sub1 sub4 &&
1291 git -C multisuper submodule add ../sub1 sub5 &&
1292 git -C multisuper commit -m "add more submodules" &&
1293 # obtain the new superproject
1294 git -C multisuper_clone pull &&
1295 git -C multisuper_clone submodule update --init &&
1296 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1297 test_cmp expect2 actual
1300 test_expect_success
'init properly sets the config' '
1301 test_when_finished "rm -rf multisuper_clone" &&
1302 git clone --recurse-submodules="." \
1303 --recurse-submodules=":(exclude)sub0" \
1304 multisuper multisuper_clone &&
1306 git -C multisuper_clone submodule init -- sub0 sub1 &&
1307 git -C multisuper_clone config --get submodule.sub0.active &&
1308 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1311 test_expect_success
'recursive clone respects -q' '
1312 test_when_finished "rm -rf multisuper_clone" &&
1313 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1314 test_must_be_empty actual