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
'add aborts on repository with no commits' '
50 cat >expect <<-\EOF &&
51 '"'repo-no-commits'"' does not have a commit checked out
53 git init repo-no-commits &&
54 test_must_fail git submodule add ../a ./repo-no-commits 2>actual &&
55 test_i18ncmp expect actual
58 test_expect_success
'setup - repository in init subdirectory' '
65 git commit -m "submodule commit 1" &&
66 git tag -a -m "rev-1" rev-1
70 test_expect_success
'setup - commit with gitlink' '
74 git commit -m "super commit 1"
77 test_expect_success
'setup - hide init subdirectory' '
81 test_expect_success
'setup - repository to add submodules to' '
83 git init addtest-ignore
86 # The 'submodule add' tests need some repository to add as a submodule.
87 # The trash directory is a good one as any. We need to canonicalize
88 # the name, though, as some tests compare it to the absolute path git
89 # generates, which will expand symbolic links.
93 git for-each-ref
--format='%(refname)' 'refs/heads/*'
102 listbranches
>"$dotdot/heads" &&
103 { git symbolic-ref HEAD ||
:; } >"$dotdot/head" &&
104 git rev-parse HEAD
>"$dotdot/head-sha1" &&
105 git update-index
--refresh &&
106 git diff-files
--exit-code &&
107 git clean
-n -d -x >"$dotdot/untracked"
111 test_expect_success
'submodule add' '
112 echo "refs/heads/master" >expect &&
116 git submodule add -q "$submodurl" submod >actual &&
117 test_must_be_empty actual &&
118 echo "gitdir: ../.git/modules/submod" >expect &&
119 test_cmp expect submod/.git &&
122 git config core.worktree >actual &&
123 echo "../../../submod" >expect &&
124 test_cmp expect actual &&
130 rm -f heads head untracked &&
131 inspect addtest/submod ../.. &&
132 test_cmp expect heads &&
133 test_cmp expect head &&
134 test_must_be_empty untracked
137 test_expect_success
'setup parent and one repository' '
138 test_create_repo parent &&
139 test_commit -C parent one
142 test_expect_success
'redirected submodule add does not show progress' '
143 git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
146 test_i18ngrep ! "Checking connectivity" err
149 test_expect_success
'redirected submodule add --progress does show progress' '
150 git -C addtest submodule add --progress "file://$submodurl/parent" \
151 submod-redirected-progress 2>err && \
155 test_expect_success
'submodule add to .gitignored path fails' '
158 cat <<-\EOF >expect &&
159 The following paths are ignored by one of your .gitignore files:
161 hint: Use -f if you really want to add them.
162 hint: Turn this message off by running
163 hint: "git config advice.addIgnoredFile false"
165 # Does not use test_commit due to the ignore
166 echo "*" > .gitignore &&
167 git add --force .gitignore &&
168 git commit -m"Ignore everything" &&
169 ! git submodule add "$submodurl" submod >actual 2>&1 &&
170 test_i18ncmp expect actual
174 test_expect_success
'submodule add to .gitignored path with --force' '
177 git submodule add --force "$submodurl" submod
181 test_expect_success
'submodule add to reconfigure existing submodule with --force' '
184 bogus_url="$(pwd)/bogus-url" &&
185 git submodule add --force "$bogus_url" submod &&
186 git submodule add --force -b initial "$submodurl" submod-branch &&
187 test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" &&
188 test "$bogus_url" = "$(git config submodule.submod.url)" &&
190 git submodule add --force "$submodurl" submod &&
191 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
192 test "$submodurl" = "$(git config submodule.submod.url)"
196 test_expect_success
'submodule add relays add --dry-run stderr' '
197 test_when_finished "rm -rf addtest/.git/index.lock" &&
200 : >.git/index.lock &&
201 ! git submodule add "$submodurl" sub-while-locked 2>output.err &&
202 test_i18ngrep "^fatal: .*index\.lock" output.err &&
203 test_path_is_missing sub-while-locked
207 test_expect_success
'submodule add --branch' '
208 echo "refs/heads/initial" >expect-head &&
209 cat <<-\EOF >expect-heads &&
216 git submodule add -b initial "$submodurl" submod-branch &&
217 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
221 rm -f heads head untracked &&
222 inspect addtest/submod-branch ../.. &&
223 test_cmp expect-heads heads &&
224 test_cmp expect-head head &&
225 test_must_be_empty untracked
228 test_expect_success
'submodule add with ./ in path' '
229 echo "refs/heads/master" >expect &&
233 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
237 rm -f heads head untracked &&
238 inspect addtest/dotsubmod/frotz ../../.. &&
239 test_cmp expect heads &&
240 test_cmp expect head &&
241 test_must_be_empty untracked
244 test_expect_success
'submodule add with /././ in path' '
245 echo "refs/heads/master" >expect &&
249 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
253 rm -f heads head untracked &&
254 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
255 test_cmp expect heads &&
256 test_cmp expect head &&
257 test_must_be_empty untracked
260 test_expect_success
'submodule add with // in path' '
261 echo "refs/heads/master" >expect &&
265 git submodule add "$submodurl" slashslashsubmod///frotz// &&
269 rm -f heads head untracked &&
270 inspect addtest/slashslashsubmod/frotz ../../.. &&
271 test_cmp expect heads &&
272 test_cmp expect head &&
273 test_must_be_empty untracked
276 test_expect_success
'submodule add with /.. in path' '
277 echo "refs/heads/master" >expect &&
281 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
285 rm -f heads head untracked &&
286 inspect addtest/realsubmod ../.. &&
287 test_cmp expect heads &&
288 test_cmp expect head &&
289 test_must_be_empty untracked
292 test_expect_success
'submodule add with ./, /.. and // in path' '
293 echo "refs/heads/master" >expect &&
297 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
301 rm -f heads head untracked &&
302 inspect addtest/realsubmod2 ../.. &&
303 test_cmp expect heads &&
304 test_cmp expect head &&
305 test_must_be_empty untracked
308 test_expect_success
!CYGWIN
'submodule add with \\ in path' '
309 test_when_finished "rm -rf parent sub\\with\\backslash" &&
311 # Initialize a repo with a backslash in its name
312 git init sub\\with\\backslash &&
313 touch sub\\with\\backslash/empty.file &&
314 git -C sub\\with\\backslash add empty.file &&
315 git -C sub\\with\\backslash commit -m "Added empty.file" &&
317 # Add that repository as a submodule
319 git -C parent submodule add ../sub\\with\\backslash
322 test_expect_success
'submodule add in subdirectory' '
323 echo "refs/heads/master" >expect &&
328 git submodule add "$submodurl" ../realsubmod3 &&
332 rm -f heads head untracked &&
333 inspect addtest/realsubmod3 ../.. &&
334 test_cmp expect heads &&
335 test_cmp expect head &&
336 test_must_be_empty untracked
339 test_expect_success
'submodule add in subdirectory with relative path should fail' '
342 test_must_fail git submodule add ../../ submod3 2>../../output.err
344 test_i18ngrep toplevel output.err
347 test_expect_success
'setup - add an example entry to .gitmodules' '
348 git config --file=.gitmodules submodule.example.url git://example.com/init.git
351 test_expect_success
'status should fail for unmapped paths' '
352 test_must_fail git submodule status
355 test_expect_success
'setup - map path in .gitmodules' '
356 cat <<\EOF >expect &&
357 [submodule "example"]
358 url = git://example.com/init.git
362 git config --file=.gitmodules submodule.example.path init &&
364 test_cmp expect .gitmodules
367 test_expect_success
'status should only print one line' '
368 git submodule status >lines &&
369 test_line_count = 1 lines
372 test_expect_success
'status from subdirectory should have the same SHA1' '
373 test_when_finished "rmdir addtest/subdir" &&
377 git submodule status >output &&
378 awk "{print \$1}" <output >expect &&
380 git submodule status >../output &&
381 awk "{print \$1}" <../output >../actual &&
382 test_cmp ../expect ../actual &&
383 git -C ../submod checkout HEAD^ &&
384 git submodule status >../output &&
385 awk "{print \$1}" <../output >../actual2 &&
387 git submodule status >output &&
388 awk "{print \$1}" <output >expect2 &&
389 test_cmp expect2 actual2 &&
390 ! test_cmp actual actual2
394 test_expect_success
'setup - fetch commit name from submodule' '
395 rev1=$(cd .subrepo && git rev-parse HEAD) &&
396 printf "rev1: %s\n" "$rev1" &&
400 test_expect_success
'status should initially be "missing"' '
401 git submodule status >lines &&
405 test_expect_success
'init should register submodule url in .git/config' '
406 echo git://example.com/init.git >expect &&
408 git submodule init &&
409 git config submodule.example.url >url &&
410 git config submodule.example.url ./.subrepo &&
415 test_failure_with_unknown_submodule
() {
416 test_must_fail git submodule
$1 no-such-submodule
2>output.err
&&
417 test_i18ngrep
"^error: .*no-such-submodule" output.err
420 test_expect_success
'init should fail with unknown submodule' '
421 test_failure_with_unknown_submodule init
424 test_expect_success
'update should fail with unknown submodule' '
425 test_failure_with_unknown_submodule update
428 test_expect_success
'status should fail with unknown submodule' '
429 test_failure_with_unknown_submodule status
432 test_expect_success
'sync should fail with unknown submodule' '
433 test_failure_with_unknown_submodule sync
436 test_expect_success
'update should fail when path is used by a file' '
437 echo hello >expect &&
439 echo "hello" >init &&
440 test_must_fail git submodule update &&
445 test_expect_success
'update should fail when path is used by a nonempty directory' '
446 echo hello >expect &&
450 echo "hello" >init/a &&
452 test_must_fail git submodule update &&
454 test_cmp expect init/a
457 test_expect_success
'update should work when path is an empty dir' '
460 echo "$rev1" >expect &&
463 git submodule update -q >update.out &&
464 test_must_be_empty update.out &&
467 test_cmp expect head-sha1
470 test_expect_success
'status should be "up-to-date" after update' '
471 git submodule status >list &&
475 test_expect_success
'status "up-to-date" from subdirectory' '
479 git submodule status >../list
481 grep "^ $rev1" list &&
482 grep "\\.\\./init" list
485 test_expect_success
'status "up-to-date" from subdirectory with path' '
489 git submodule status ../init >../list
491 grep "^ $rev1" list &&
492 grep "\\.\\./init" list
495 test_expect_success
'status should be "modified" after submodule commit' '
500 git commit -m "submodule commit 2"
503 rev2=$(cd init && git rev-parse HEAD) &&
505 git submodule status >list &&
510 test_expect_success
'the --cached sha1 should be rev1' '
511 git submodule --cached status >list &&
515 test_expect_success
'git diff should report the SHA1 of the new submodule commit' '
517 grep "^+Subproject commit $rev2" diff
520 test_expect_success
'update should checkout rev1' '
522 echo "$rev1" >expect &&
524 git submodule update init &&
527 test_cmp expect head-sha1
530 test_expect_success
'status should be "up-to-date" after update' '
531 git submodule status >list &&
535 test_expect_success
'checkout superproject with subproject already present' '
536 git checkout initial &&
540 test_expect_success
'apply submodule diff' '
546 git commit -m "change subproject"
548 git update-index --add init &&
549 git commit -m "change init" &&
550 git format-patch -1 --stdout >P.diff &&
551 git checkout second &&
552 git apply --index P.diff &&
554 git diff --cached master >staged &&
555 test_must_be_empty staged
558 test_expect_success
'update --init' '
560 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
561 git config --remove-section submodule.example &&
562 test_must_fail git config submodule.example.url &&
564 git submodule update init 2> update.out &&
565 test_i18ngrep "not initialized" update.out &&
566 test_must_fail git rev-parse --resolve-git-dir init/.git &&
568 git submodule update --init init &&
569 git rev-parse --resolve-git-dir init/.git
572 test_expect_success
'update --init from subdirectory' '
574 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
575 git config --remove-section submodule.example &&
576 test_must_fail git config submodule.example.url &&
581 git submodule update ../init 2>update.out &&
582 test_i18ngrep "not initialized" update.out &&
583 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
585 git submodule update --init ../init
587 git rev-parse --resolve-git-dir init/.git
590 test_expect_success
'do not add files from a submodule' '
593 test_must_fail git add init/a
597 test_expect_success
'gracefully add/reset submodule with a trailing slash' '
600 git commit -m "commit subproject" init &&
604 git diff --exit-code --cached init &&
606 git commit -m update a >/dev/null &&
607 git rev-parse HEAD) &&
609 test_must_fail git diff --exit-code --cached init &&
610 test $commit = $(git ls-files --stage |
611 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
613 git diff --exit-code --cached init
617 test_expect_success
'ls-files gracefully handles trailing slash' '
619 test "init" = "$(git ls-files init/)"
623 test_expect_success
'moving to a commit without submodule does not leave empty dir' '
627 git checkout initial &&
632 test_expect_success
'submodule <invalid-subcommand> fails' '
633 test_must_fail git submodule no-such-subcommand
636 test_expect_success
'add submodules without specifying an explicit path' '
643 git commit -m "repo commit 1"
645 git clone --bare repo/ bare.git &&
648 git submodule add "$submodurl/repo" &&
649 git config -f .gitmodules submodule.repo.path repo &&
650 git submodule add "$submodurl/bare.git" &&
651 git config -f .gitmodules submodule.bare.path bare
655 test_expect_success
'add should fail when path is used by a file' '
659 test_must_fail git submodule add "$submodurl/repo" file
663 test_expect_success
'add should fail when path is used by an existing directory' '
667 test_must_fail git submodule add "$submodurl/repo" empty-dir
671 test_expect_success
'use superproject as upstream when path is relative and no url is set there' '
674 git submodule add ../repo relative &&
675 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
676 git submodule sync relative &&
677 test "$(git config submodule.relative.url)" = "$submodurl/repo"
681 test_expect_success
'set up for relative path tests' '
693 git config -f .gitmodules submodule.sub.path sub &&
694 git config -f .gitmodules submodule.sub.url ../subrepo &&
695 cp .git/config pristine-.git-config &&
696 cp .gitmodules pristine-.gitmodules
700 test_expect_success
'../subrepo works with URL - ssh://hostname/repo' '
703 cp pristine-.git-config .git/config &&
704 cp pristine-.gitmodules .gitmodules &&
705 git config remote.origin.url ssh://hostname/repo &&
706 git submodule init &&
707 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
711 test_expect_success
'../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
714 cp pristine-.git-config .git/config &&
715 cp pristine-.gitmodules .gitmodules &&
716 git config remote.origin.url ssh://hostname:22/repo &&
717 git submodule init &&
718 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
722 # About the choice of the path in the next test:
723 # - double-slash side-steps path mangling issues on Windows
724 # - it is still an absolute local path
725 # - there cannot be a server with a blank in its name just in case the
726 # path is used erroneously to access a //server/share style path
727 test_expect_success
'../subrepo path works with local path - //somewhere else/repo' '
730 cp pristine-.git-config .git/config &&
731 cp pristine-.gitmodules .gitmodules &&
732 git config remote.origin.url "//somewhere else/repo" &&
733 git submodule init &&
734 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
738 test_expect_success
'../subrepo works with file URL - file:///tmp/repo' '
741 cp pristine-.git-config .git/config &&
742 cp pristine-.gitmodules .gitmodules &&
743 git config remote.origin.url file:///tmp/repo &&
744 git submodule init &&
745 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
749 test_expect_success
'../subrepo works with helper URL- helper:://hostname/repo' '
752 cp pristine-.git-config .git/config &&
753 cp pristine-.gitmodules .gitmodules &&
754 git config remote.origin.url helper:://hostname/repo &&
755 git submodule init &&
756 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
760 test_expect_success
'../subrepo works with scp-style URL - user@host:repo' '
763 cp pristine-.git-config .git/config &&
764 git config remote.origin.url user@host:repo &&
765 git submodule init &&
766 test "$(git config submodule.sub.url)" = user@host:subrepo
770 test_expect_success
'../subrepo works with scp-style URL - user@host:path/to/repo' '
773 cp pristine-.git-config .git/config &&
774 cp pristine-.gitmodules .gitmodules &&
775 git config remote.origin.url user@host:path/to/repo &&
776 git submodule init &&
777 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
781 test_expect_success
'../subrepo works with relative local path - foo' '
784 cp pristine-.git-config .git/config &&
785 cp pristine-.gitmodules .gitmodules &&
786 git config remote.origin.url foo &&
787 # actual: fails with an error
788 git submodule init &&
789 test "$(git config submodule.sub.url)" = subrepo
793 test_expect_success
'../subrepo works with relative local path - foo/bar' '
796 cp pristine-.git-config .git/config &&
797 cp pristine-.gitmodules .gitmodules &&
798 git config remote.origin.url foo/bar &&
799 git submodule init &&
800 test "$(git config submodule.sub.url)" = foo/subrepo
804 test_expect_success
'../subrepo works with relative local path - ./foo' '
807 cp pristine-.git-config .git/config &&
808 cp pristine-.gitmodules .gitmodules &&
809 git config remote.origin.url ./foo &&
810 git submodule init &&
811 test "$(git config submodule.sub.url)" = subrepo
815 test_expect_success
'../subrepo works with relative local path - ./foo/bar' '
818 cp pristine-.git-config .git/config &&
819 cp pristine-.gitmodules .gitmodules &&
820 git config remote.origin.url ./foo/bar &&
821 git submodule init &&
822 test "$(git config submodule.sub.url)" = foo/subrepo
826 test_expect_success
'../subrepo works with relative local path - ../foo' '
829 cp pristine-.git-config .git/config &&
830 cp pristine-.gitmodules .gitmodules &&
831 git config remote.origin.url ../foo &&
832 git submodule init &&
833 test "$(git config submodule.sub.url)" = ../subrepo
837 test_expect_success
'../subrepo works with relative local path - ../foo/bar' '
840 cp pristine-.git-config .git/config &&
841 cp pristine-.gitmodules .gitmodules &&
842 git config remote.origin.url ../foo/bar &&
843 git submodule init &&
844 test "$(git config submodule.sub.url)" = ../foo/subrepo
848 test_expect_success
'../bar/a/b/c works with relative local path - ../foo/bar.git' '
851 cp pristine-.git-config .git/config &&
852 cp pristine-.gitmodules .gitmodules &&
854 (cd a/b/c && git init && test_commit msg) &&
855 git config remote.origin.url ../foo/bar.git &&
856 git submodule add ../bar/a/b/c ./a/b/c &&
857 git submodule init &&
858 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
862 test_expect_success
'moving the superproject does not break submodules' '
865 git submodule status >expect
867 mv addtest addtest2 &&
870 git submodule status >actual &&
871 test_cmp expect actual
875 test_expect_success
'moving the submodule does not break the superproject' '
880 sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect &&
881 mv addtest2/repo addtest2/repo.bak &&
882 test_when_finished "mv addtest2/repo.bak addtest2/repo" &&
887 test_cmp expect actual
890 test_expect_success
'submodule add --name allows to replace a submodule with another at the same path' '
895 echo "$submodurl/repo" >expect &&
896 git config remote.origin.url >actual &&
897 test_cmp expect actual &&
898 echo "gitdir: ../.git/modules/repo" >expect &&
903 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
904 test_must_be_empty actual &&
905 echo "gitdir: ../.git/modules/submod" >expect &&
906 test_cmp expect submod/.git &&
909 echo "$submodurl/bare.git" >expect &&
910 git config remote.origin.url >actual &&
911 test_cmp expect actual &&
912 echo "gitdir: ../.git/modules/repo_new" >expect &&
915 echo "repo" >expect &&
916 test_must_fail git config -f .gitmodules submodule.repo.path &&
917 git config -f .gitmodules submodule.repo_new.path >actual &&
918 test_cmp expect actual&&
919 echo "$submodurl/repo" >expect &&
920 test_must_fail git config -f .gitmodules submodule.repo.url &&
921 echo "$submodurl/bare.git" >expect &&
922 git config -f .gitmodules submodule.repo_new.url >actual &&
923 test_cmp expect actual &&
924 echo "$submodurl/repo" >expect &&
925 git config submodule.repo.url >actual &&
926 test_cmp expect actual &&
927 echo "$submodurl/bare.git" >expect &&
928 git config submodule.repo_new.url >actual &&
929 test_cmp expect actual
933 test_expect_success
'recursive relative submodules stay relative' '
934 test_when_finished "rm -rf super clone2 subsub sub3" &&
941 git commit -m "initial commit"
949 git commit -m "initial commit" &&
950 git submodule add ../subsub dirdir/subsub &&
951 git commit -m "add submodule subsub"
959 git commit -m "initial commit" &&
960 git submodule add ../sub3 &&
961 git commit -m "add submodule sub"
963 git clone super clone2 &&
966 git submodule update --init --recursive &&
967 echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect &&
968 echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect
970 test_cmp clone2/sub3/.git_expect clone2/sub3/.git &&
971 test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git
974 test_expect_success
'submodule add with an existing name fails unless forced' '
979 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
981 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
982 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
983 echo "$submodurl/bare.git" >expect &&
984 git config submodule.repo_new.url >actual &&
985 test_cmp expect actual &&
986 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
988 echo "repo" >expect &&
989 git config -f .gitmodules submodule.repo_new.path >actual &&
990 test_cmp expect actual&&
991 echo "$submodurl/repo.git" >expect &&
992 git config -f .gitmodules submodule.repo_new.url >actual &&
993 test_cmp expect actual &&
994 echo "$submodurl/repo.git" >expect &&
995 git config submodule.repo_new.url >actual &&
996 test_cmp expect actual
1000 test_expect_success
'set up a second submodule' '
1001 git submodule add ./init2 example2 &&
1002 git commit -m "submodule example2 added"
1005 test_expect_success
'submodule deinit works on repository without submodules' '
1006 test_when_finished "rm -rf newdirectory" &&
1007 mkdir newdirectory &&
1013 git commit -m "repo should not be empty" &&
1014 git submodule deinit . &&
1015 git submodule deinit --all
1019 test_expect_success
'submodule deinit should remove the whole submodule section from .git/config' '
1020 git config submodule.example.foo bar &&
1021 git config submodule.example2.frotz nitfol &&
1022 git submodule deinit init &&
1023 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1024 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1025 test -f example2/.git &&
1029 test_expect_success
'submodule deinit should unset core.worktree' '
1030 test_path_is_file .git/modules/example/config &&
1031 test_must_fail git config -f .git/modules/example/config core.worktree
1034 test_expect_success
'submodule deinit from subdirectory' '
1035 git submodule update --init &&
1036 git config submodule.example.foo bar &&
1040 git submodule deinit ../init >../output
1042 test_i18ngrep "\\.\\./init" output &&
1043 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1044 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
1045 test -f example2/.git &&
1049 test_expect_success
'submodule deinit . deinits all initialized submodules' '
1050 git submodule update --init &&
1051 git config submodule.example.foo bar &&
1052 git config submodule.example2.frotz nitfol &&
1053 test_must_fail git submodule deinit &&
1054 git submodule deinit . >actual &&
1055 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1056 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1057 test_i18ngrep "Cleared directory .init" actual &&
1058 test_i18ngrep "Cleared directory .example2" actual &&
1062 test_expect_success
'submodule deinit --all deinits all initialized submodules' '
1063 git submodule update --init &&
1064 git config submodule.example.foo bar &&
1065 git config submodule.example2.frotz nitfol &&
1066 test_must_fail git submodule deinit &&
1067 git submodule deinit --all >actual &&
1068 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1069 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1070 test_i18ngrep "Cleared directory .init" actual &&
1071 test_i18ngrep "Cleared directory .example2" actual &&
1075 test_expect_success
'submodule deinit deinits a submodule when its work tree is missing or empty' '
1076 git submodule update --init &&
1077 rm -rf init example2/* example2/.git &&
1078 git submodule deinit init example2 >actual &&
1079 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1080 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
1081 test_i18ngrep ! "Cleared directory .init" actual &&
1082 test_i18ngrep "Cleared directory .example2" actual &&
1086 test_expect_success
'submodule deinit fails when the submodule contains modifications unless forced' '
1087 git submodule update --init &&
1089 test_must_fail git submodule deinit init &&
1090 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1091 test -f example2/.git &&
1092 git submodule deinit -f init >actual &&
1093 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1094 test_i18ngrep "Cleared directory .init" actual &&
1098 test_expect_success
'submodule deinit fails when the submodule contains untracked files unless forced' '
1099 git submodule update --init &&
1100 echo X >>init/untracked &&
1101 test_must_fail git submodule deinit init &&
1102 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1103 test -f example2/.git &&
1104 git submodule deinit -f init >actual &&
1105 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1106 test_i18ngrep "Cleared directory .init" actual &&
1110 test_expect_success
'submodule deinit fails when the submodule HEAD does not match unless forced' '
1111 git submodule update --init &&
1116 test_must_fail git submodule deinit init &&
1117 test -n "$(git config --get-regexp "submodule\.example\.")" &&
1118 test -f example2/.git &&
1119 git submodule deinit -f init >actual &&
1120 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1121 test_i18ngrep "Cleared directory .init" actual &&
1125 test_expect_success
'submodule deinit is silent when used on an uninitialized submodule' '
1126 git submodule update --init &&
1127 git submodule deinit init >actual &&
1128 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
1129 test_i18ngrep "Cleared directory .init" actual &&
1130 git submodule deinit init >actual &&
1131 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1132 test_i18ngrep "Cleared directory .init" actual &&
1133 git submodule deinit . >actual &&
1134 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1135 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
1136 test_i18ngrep "Cleared directory .init" actual &&
1137 git submodule deinit . >actual &&
1138 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1139 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1140 test_i18ngrep "Cleared directory .init" actual &&
1141 git submodule deinit --all >actual &&
1142 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1143 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
1144 test_i18ngrep "Cleared directory .init" actual &&
1148 test_expect_success
'submodule deinit fails when submodule has a .git directory even when forced' '
1149 git submodule update --init &&
1153 cp -R ../.git/modules/example .git &&
1154 GIT_WORK_TREE=. git config --unset core.worktree
1156 test_must_fail git submodule deinit init &&
1157 test_must_fail git submodule deinit -f init &&
1158 test -d init/.git &&
1159 test -n "$(git config --get-regexp "submodule\.example\.")"
1162 test_expect_success
'submodule with UTF-8 name' '
1163 svname=$(printf "\303\245 \303\244\303\266") &&
1170 git commit -m "init sub"
1172 git submodule add ./"$svname" &&
1173 git submodule >&2 &&
1174 test -n "$(git submodule | grep "$svname")"
1177 test_expect_success
'submodule add clone shallow submodule' '
1183 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1186 test 1 = $(git log --oneline | wc -l)
1191 test_expect_success
'submodule helper list is not confused by common prefixes' '
1196 echo hi >testfile2 &&
1198 git commit -m "test1"
1204 echo hello >testfile1 &&
1206 git commit -m "test2"
1208 git submodule add /dir1/b dir1/b &&
1209 git submodule add /dir2/b dir2/b &&
1210 git commit -m "first submodule commit" &&
1211 git submodule--helper list dir1/b |cut -c51- >actual &&
1212 echo "dir1/b" >expect &&
1213 test_cmp expect actual
1216 test_expect_success
'setup superproject with submodules' '
1218 test_commit -C sub1 test &&
1219 test_commit -C sub1 test2 &&
1220 git init multisuper &&
1221 git -C multisuper submodule add ../sub1 sub0 &&
1222 git -C multisuper submodule add ../sub1 sub1 &&
1223 git -C multisuper submodule add ../sub1 sub2 &&
1224 git -C multisuper submodule add ../sub1 sub3 &&
1225 git -C multisuper commit -m "add some submodules"
1235 test_expect_success
'submodule update --init with a specification' '
1236 test_when_finished "rm -rf multisuper_clone" &&
1238 git clone file://"$pwd"/multisuper multisuper_clone &&
1239 git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
1240 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1241 test_cmp expect actual
1244 test_expect_success
'submodule update --init with submodule.active set' '
1245 test_when_finished "rm -rf multisuper_clone" &&
1247 git clone file://"$pwd"/multisuper multisuper_clone &&
1248 git -C multisuper_clone config submodule.active "." &&
1249 git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
1250 git -C multisuper_clone submodule update --init &&
1251 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1252 test_cmp expect actual
1255 test_expect_success
'submodule update and setting submodule.<name>.active' '
1256 test_when_finished "rm -rf multisuper_clone" &&
1258 git clone file://"$pwd"/multisuper multisuper_clone &&
1259 git -C multisuper_clone config --bool submodule.sub0.active "true" &&
1260 git -C multisuper_clone config --bool submodule.sub1.active "false" &&
1261 git -C multisuper_clone config --bool submodule.sub2.active "true" &&
1263 cat >expect <<-\EOF &&
1269 git -C multisuper_clone submodule update &&
1270 git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
1271 test_cmp expect actual
1274 test_expect_success
'clone active submodule without submodule url set' '
1275 test_when_finished "rm -rf test/test" &&
1277 # another dir breaks accidental relative paths still being correct
1278 git clone file://"$pwd"/multisuper test/test &&
1281 git config submodule.active "." &&
1283 # do not pass --init flag, as the submodule is already active:
1284 git submodule update &&
1285 git submodule status >actual_raw &&
1287 cut -c 1,43- actual_raw >actual &&
1288 cat >expect <<-\EOF &&
1294 test_cmp expect actual
1298 test_expect_success
'clone --recurse-submodules with a pathspec works' '
1299 test_when_finished "rm -rf multisuper_clone" &&
1300 cat >expected <<-\EOF &&
1307 git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
1308 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1309 test_cmp expected actual
1312 test_expect_success
'clone with multiple --recurse-submodules options' '
1313 test_when_finished "rm -rf multisuper_clone" &&
1314 cat >expect <<-\EOF &&
1321 git clone --recurse-submodules="." \
1322 --recurse-submodules=":(exclude)sub0" \
1323 --recurse-submodules=":(exclude)sub2" \
1324 multisuper multisuper_clone &&
1325 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1326 test_cmp expect actual
1329 test_expect_success
'clone and subsequent updates correctly auto-initialize submodules' '
1330 test_when_finished "rm -rf multisuper_clone" &&
1331 cat <<-\EOF >expect &&
1338 cat <<-\EOF >expect2 &&
1347 git clone --recurse-submodules="." \
1348 --recurse-submodules=":(exclude)sub0" \
1349 --recurse-submodules=":(exclude)sub2" \
1350 --recurse-submodules=":(exclude)sub4" \
1351 multisuper multisuper_clone &&
1353 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1354 test_cmp expect actual &&
1356 git -C multisuper submodule add ../sub1 sub4 &&
1357 git -C multisuper submodule add ../sub1 sub5 &&
1358 git -C multisuper commit -m "add more submodules" &&
1359 # obtain the new superproject
1360 git -C multisuper_clone pull &&
1361 git -C multisuper_clone submodule update --init &&
1362 git -C multisuper_clone submodule status |cut -c1,43- >actual &&
1363 test_cmp expect2 actual
1366 test_expect_success
'init properly sets the config' '
1367 test_when_finished "rm -rf multisuper_clone" &&
1368 git clone --recurse-submodules="." \
1369 --recurse-submodules=":(exclude)sub0" \
1370 multisuper multisuper_clone &&
1372 git -C multisuper_clone submodule init -- sub0 sub1 &&
1373 git -C multisuper_clone config --get submodule.sub0.active &&
1374 test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1377 test_expect_success
'recursive clone respects -q' '
1378 test_when_finished "rm -rf multisuper_clone" &&
1379 git clone -q --recurse-submodules multisuper multisuper_clone >actual &&
1380 test_must_be_empty actual