submodule deinit: require '--all' instead of '.' for all submodules
[git.git] / t / t7400-submodule-basic.sh
blobcc3cca09f3743eab042e61804048c4b7b9ef6ad8
1 #!/bin/sh
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.
12 . ./test-lib.sh
14 test_expect_success 'submodule deinit works on empty repository' '
15 git submodule deinit --all
18 test_expect_success 'setup - initial commit' '
19 >t &&
20 git add t &&
21 git commit -m "initial commit" &&
22 git branch initial
25 test_expect_success 'configuration parsing' '
26 test_when_finished "rm -f .gitmodules" &&
27 cat >.gitmodules <<-\EOF &&
28 [submodule "s"]
29 path
30 ignore
31 EOF
32 test_must_fail git status
35 test_expect_success 'setup - repository in init subdirectory' '
36 mkdir init &&
38 cd init &&
39 git init &&
40 echo a >a &&
41 git add a &&
42 git commit -m "submodule commit 1" &&
43 git tag -a -m "rev-1" rev-1
47 test_expect_success 'setup - commit with gitlink' '
48 echo a >a &&
49 echo z >z &&
50 git add a init z &&
51 git commit -m "super commit 1"
54 test_expect_success 'setup - hide init subdirectory' '
55 mv init .subrepo
58 test_expect_success 'setup - repository to add submodules to' '
59 git init addtest &&
60 git init addtest-ignore
63 # The 'submodule add' tests need some repository to add as a submodule.
64 # The trash directory is a good one as any. We need to canonicalize
65 # the name, though, as some tests compare it to the absolute path git
66 # generates, which will expand symbolic links.
67 submodurl=$(pwd -P)
69 listbranches() {
70 git for-each-ref --format='%(refname)' 'refs/heads/*'
73 inspect() {
74 dir=$1 &&
75 dotdot="${2:-..}" &&
78 cd "$dir" &&
79 listbranches >"$dotdot/heads" &&
80 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
81 git rev-parse HEAD >"$dotdot/head-sha1" &&
82 git update-index --refresh &&
83 git diff-files --exit-code &&
84 git clean -n -d -x >"$dotdot/untracked"
88 test_expect_success 'submodule add' '
89 echo "refs/heads/master" >expect &&
90 >empty &&
93 cd addtest &&
94 git submodule add -q "$submodurl" submod >actual &&
95 test_must_be_empty actual &&
96 echo "gitdir: ../.git/modules/submod" >expect &&
97 test_cmp expect submod/.git &&
99 cd submod &&
100 git config core.worktree >actual &&
101 echo "../../../submod" >expect &&
102 test_cmp expect actual &&
103 rm -f actual expect
104 ) &&
105 git submodule init
106 ) &&
108 rm -f heads head untracked &&
109 inspect addtest/submod ../.. &&
110 test_cmp expect heads &&
111 test_cmp expect head &&
112 test_cmp empty untracked
115 test_expect_success 'submodule add to .gitignored path fails' '
117 cd addtest-ignore &&
118 cat <<-\EOF >expect &&
119 The following path is ignored by one of your .gitignore files:
120 submod
121 Use -f if you really want to add it.
123 # Does not use test_commit due to the ignore
124 echo "*" > .gitignore &&
125 git add --force .gitignore &&
126 git commit -m"Ignore everything" &&
127 ! git submodule add "$submodurl" submod >actual 2>&1 &&
128 test_i18ncmp expect actual
132 test_expect_success 'submodule add to .gitignored path with --force' '
134 cd addtest-ignore &&
135 git submodule add --force "$submodurl" submod
139 test_expect_success 'submodule add --branch' '
140 echo "refs/heads/initial" >expect-head &&
141 cat <<-\EOF >expect-heads &&
142 refs/heads/initial
143 refs/heads/master
145 >empty &&
148 cd addtest &&
149 git submodule add -b initial "$submodurl" submod-branch &&
150 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
151 git submodule init
152 ) &&
154 rm -f heads head untracked &&
155 inspect addtest/submod-branch ../.. &&
156 test_cmp expect-heads heads &&
157 test_cmp expect-head head &&
158 test_cmp empty untracked
161 test_expect_success 'submodule add with ./ in path' '
162 echo "refs/heads/master" >expect &&
163 >empty &&
166 cd addtest &&
167 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
168 git submodule init
169 ) &&
171 rm -f heads head untracked &&
172 inspect addtest/dotsubmod/frotz ../../.. &&
173 test_cmp expect heads &&
174 test_cmp expect head &&
175 test_cmp empty untracked
178 test_expect_success 'submodule add with /././ in path' '
179 echo "refs/heads/master" >expect &&
180 >empty &&
183 cd addtest &&
184 git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ &&
185 git submodule init
186 ) &&
188 rm -f heads head untracked &&
189 inspect addtest/dotslashdotsubmod/frotz ../../.. &&
190 test_cmp expect heads &&
191 test_cmp expect head &&
192 test_cmp empty untracked
195 test_expect_success 'submodule add with // in path' '
196 echo "refs/heads/master" >expect &&
197 >empty &&
200 cd addtest &&
201 git submodule add "$submodurl" slashslashsubmod///frotz// &&
202 git submodule init
203 ) &&
205 rm -f heads head untracked &&
206 inspect addtest/slashslashsubmod/frotz ../../.. &&
207 test_cmp expect heads &&
208 test_cmp expect head &&
209 test_cmp empty untracked
212 test_expect_success 'submodule add with /.. in path' '
213 echo "refs/heads/master" >expect &&
214 >empty &&
217 cd addtest &&
218 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
219 git submodule init
220 ) &&
222 rm -f heads head untracked &&
223 inspect addtest/realsubmod ../.. &&
224 test_cmp expect heads &&
225 test_cmp expect head &&
226 test_cmp empty untracked
229 test_expect_success 'submodule add with ./, /.. and // in path' '
230 echo "refs/heads/master" >expect &&
231 >empty &&
234 cd addtest &&
235 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
236 git submodule init
237 ) &&
239 rm -f heads head untracked &&
240 inspect addtest/realsubmod2 ../.. &&
241 test_cmp expect heads &&
242 test_cmp expect head &&
243 test_cmp empty untracked
246 test_expect_success 'submodule add in subdirectory' '
247 echo "refs/heads/master" >expect &&
248 >empty &&
250 mkdir addtest/sub &&
252 cd addtest/sub &&
253 git submodule add "$submodurl" ../realsubmod3 &&
254 git submodule init
255 ) &&
257 rm -f heads head untracked &&
258 inspect addtest/realsubmod3 ../.. &&
259 test_cmp expect heads &&
260 test_cmp expect head &&
261 test_cmp empty untracked
264 test_expect_success 'submodule add in subdirectory with relative path should fail' '
266 cd addtest/sub &&
267 test_must_fail git submodule add ../../ submod3 2>../../output.err
268 ) &&
269 test_i18ngrep toplevel output.err
272 test_expect_success 'setup - add an example entry to .gitmodules' '
273 git config --file=.gitmodules submodule.example.url git://example.com/init.git
276 test_expect_success 'status should fail for unmapped paths' '
277 test_must_fail git submodule status
280 test_expect_success 'setup - map path in .gitmodules' '
281 cat <<\EOF >expect &&
282 [submodule "example"]
283 url = git://example.com/init.git
284 path = init
287 git config --file=.gitmodules submodule.example.path init &&
289 test_cmp expect .gitmodules
292 test_expect_success 'status should only print one line' '
293 git submodule status >lines &&
294 test_line_count = 1 lines
297 test_expect_success 'setup - fetch commit name from submodule' '
298 rev1=$(cd .subrepo && git rev-parse HEAD) &&
299 printf "rev1: %s\n" "$rev1" &&
300 test -n "$rev1"
303 test_expect_success 'status should initially be "missing"' '
304 git submodule status >lines &&
305 grep "^-$rev1" lines
308 test_expect_success 'init should register submodule url in .git/config' '
309 echo git://example.com/init.git >expect &&
311 git submodule init &&
312 git config submodule.example.url >url &&
313 git config submodule.example.url ./.subrepo &&
315 test_cmp expect url
318 test_failure_with_unknown_submodule () {
319 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
320 grep "^error: .*no-such-submodule" output.err
323 test_expect_success 'init should fail with unknown submodule' '
324 test_failure_with_unknown_submodule init
327 test_expect_success 'update should fail with unknown submodule' '
328 test_failure_with_unknown_submodule update
331 test_expect_success 'status should fail with unknown submodule' '
332 test_failure_with_unknown_submodule status
335 test_expect_success 'sync should fail with unknown submodule' '
336 test_failure_with_unknown_submodule sync
339 test_expect_success 'update should fail when path is used by a file' '
340 echo hello >expect &&
342 echo "hello" >init &&
343 test_must_fail git submodule update &&
345 test_cmp expect init
348 test_expect_success 'update should fail when path is used by a nonempty directory' '
349 echo hello >expect &&
351 rm -fr init &&
352 mkdir init &&
353 echo "hello" >init/a &&
355 test_must_fail git submodule update &&
357 test_cmp expect init/a
360 test_expect_success 'update should work when path is an empty dir' '
361 rm -fr init &&
362 rm -f head-sha1 &&
363 echo "$rev1" >expect &&
365 mkdir init &&
366 git submodule update -q >update.out &&
367 test_must_be_empty update.out &&
369 inspect init &&
370 test_cmp expect head-sha1
373 test_expect_success 'status should be "up-to-date" after update' '
374 git submodule status >list &&
375 grep "^ $rev1" list
378 test_expect_success 'status "up-to-date" from subdirectory' '
379 mkdir -p sub &&
381 cd sub &&
382 git submodule status >../list
383 ) &&
384 grep "^ $rev1" list &&
385 grep "\\.\\./init" list
388 test_expect_success 'status "up-to-date" from subdirectory with path' '
389 mkdir -p sub &&
391 cd sub &&
392 git submodule status ../init >../list
393 ) &&
394 grep "^ $rev1" list &&
395 grep "\\.\\./init" list
398 test_expect_success 'status should be "modified" after submodule commit' '
400 cd init &&
401 echo b >b &&
402 git add b &&
403 git commit -m "submodule commit 2"
404 ) &&
406 rev2=$(cd init && git rev-parse HEAD) &&
407 test -n "$rev2" &&
408 git submodule status >list &&
410 grep "^+$rev2" list
413 test_expect_success 'the --cached sha1 should be rev1' '
414 git submodule --cached status >list &&
415 grep "^+$rev1" list
418 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
419 git diff >diff &&
420 grep "^+Subproject commit $rev2" diff
423 test_expect_success 'update should checkout rev1' '
424 rm -f head-sha1 &&
425 echo "$rev1" >expect &&
427 git submodule update init &&
428 inspect init &&
430 test_cmp expect head-sha1
433 test_expect_success 'status should be "up-to-date" after update' '
434 git submodule status >list &&
435 grep "^ $rev1" list
438 test_expect_success 'checkout superproject with subproject already present' '
439 git checkout initial &&
440 git checkout master
443 test_expect_success 'apply submodule diff' '
444 >empty &&
446 git branch second &&
448 cd init &&
449 echo s >s &&
450 git add s &&
451 git commit -m "change subproject"
452 ) &&
453 git update-index --add init &&
454 git commit -m "change init" &&
455 git format-patch -1 --stdout >P.diff &&
456 git checkout second &&
457 git apply --index P.diff &&
459 git diff --cached master >staged &&
460 test_cmp empty staged
463 test_expect_success 'update --init' '
464 mv init init2 &&
465 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
466 git config --remove-section submodule.example &&
467 test_must_fail git config submodule.example.url &&
469 git submodule update init > update.out &&
470 cat update.out &&
471 test_i18ngrep "not initialized" update.out &&
472 test_must_fail git rev-parse --resolve-git-dir init/.git &&
474 git submodule update --init init &&
475 git rev-parse --resolve-git-dir init/.git
478 test_expect_success 'update --init from subdirectory' '
479 mv init init2 &&
480 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
481 git config --remove-section submodule.example &&
482 test_must_fail git config submodule.example.url &&
484 mkdir -p sub &&
486 cd sub &&
487 git submodule update ../init >update.out &&
488 cat update.out &&
489 test_i18ngrep "not initialized" update.out &&
490 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
492 git submodule update --init ../init
493 ) &&
494 git rev-parse --resolve-git-dir init/.git
497 test_expect_success 'do not add files from a submodule' '
499 git reset --hard &&
500 test_must_fail git add init/a
504 test_expect_success 'gracefully add/reset submodule with a trailing slash' '
506 git reset --hard &&
507 git commit -m "commit subproject" init &&
508 (cd init &&
509 echo b > a) &&
510 git add init/ &&
511 git diff --exit-code --cached init &&
512 commit=$(cd init &&
513 git commit -m update a >/dev/null &&
514 git rev-parse HEAD) &&
515 git add init/ &&
516 test_must_fail git diff --exit-code --cached init &&
517 test $commit = $(git ls-files --stage |
518 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
519 git reset init/ &&
520 git diff --exit-code --cached init
524 test_expect_success 'ls-files gracefully handles trailing slash' '
526 test "init" = "$(git ls-files init/)"
530 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
531 rm -rf init &&
532 mkdir init &&
533 git reset --hard &&
534 git checkout initial &&
535 test ! -d init &&
536 git checkout second
539 test_expect_success 'submodule <invalid-subcommand> fails' '
540 test_must_fail git submodule no-such-subcommand
543 test_expect_success 'add submodules without specifying an explicit path' '
544 mkdir repo &&
546 cd repo &&
547 git init &&
548 echo r >r &&
549 git add r &&
550 git commit -m "repo commit 1"
551 ) &&
552 git clone --bare repo/ bare.git &&
554 cd addtest &&
555 git submodule add "$submodurl/repo" &&
556 git config -f .gitmodules submodule.repo.path repo &&
557 git submodule add "$submodurl/bare.git" &&
558 git config -f .gitmodules submodule.bare.path bare
562 test_expect_success 'add should fail when path is used by a file' '
564 cd addtest &&
565 touch file &&
566 test_must_fail git submodule add "$submodurl/repo" file
570 test_expect_success 'add should fail when path is used by an existing directory' '
572 cd addtest &&
573 mkdir empty-dir &&
574 test_must_fail git submodule add "$submodurl/repo" empty-dir
578 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
580 cd addtest &&
581 git submodule add ../repo relative &&
582 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
583 git submodule sync relative &&
584 test "$(git config submodule.relative.url)" = "$submodurl/repo"
588 test_expect_success 'set up for relative path tests' '
589 mkdir reltest &&
591 cd reltest &&
592 git init &&
593 mkdir sub &&
595 cd sub &&
596 git init &&
597 test_commit foo
598 ) &&
599 git add sub &&
600 git config -f .gitmodules submodule.sub.path sub &&
601 git config -f .gitmodules submodule.sub.url ../subrepo &&
602 cp .git/config pristine-.git-config &&
603 cp .gitmodules pristine-.gitmodules
607 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
609 cd reltest &&
610 cp pristine-.git-config .git/config &&
611 cp pristine-.gitmodules .gitmodules &&
612 git config remote.origin.url ssh://hostname/repo &&
613 git submodule init &&
614 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
618 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
620 cd reltest &&
621 cp pristine-.git-config .git/config &&
622 cp pristine-.gitmodules .gitmodules &&
623 git config remote.origin.url ssh://hostname:22/repo &&
624 git submodule init &&
625 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
629 # About the choice of the path in the next test:
630 # - double-slash side-steps path mangling issues on Windows
631 # - it is still an absolute local path
632 # - there cannot be a server with a blank in its name just in case the
633 # path is used erroneously to access a //server/share style path
634 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
636 cd reltest &&
637 cp pristine-.git-config .git/config &&
638 cp pristine-.gitmodules .gitmodules &&
639 git config remote.origin.url "//somewhere else/repo" &&
640 git submodule init &&
641 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
645 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
647 cd reltest &&
648 cp pristine-.git-config .git/config &&
649 cp pristine-.gitmodules .gitmodules &&
650 git config remote.origin.url file:///tmp/repo &&
651 git submodule init &&
652 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
656 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
658 cd reltest &&
659 cp pristine-.git-config .git/config &&
660 cp pristine-.gitmodules .gitmodules &&
661 git config remote.origin.url helper:://hostname/repo &&
662 git submodule init &&
663 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
667 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
669 cd reltest &&
670 cp pristine-.git-config .git/config &&
671 git config remote.origin.url user@host:repo &&
672 git submodule init &&
673 test "$(git config submodule.sub.url)" = user@host:subrepo
677 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
679 cd reltest &&
680 cp pristine-.git-config .git/config &&
681 cp pristine-.gitmodules .gitmodules &&
682 git config remote.origin.url user@host:path/to/repo &&
683 git submodule init &&
684 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
688 test_expect_success '../subrepo works with relative local path - foo' '
690 cd reltest &&
691 cp pristine-.git-config .git/config &&
692 cp pristine-.gitmodules .gitmodules &&
693 git config remote.origin.url foo &&
694 # actual: fails with an error
695 git submodule init &&
696 test "$(git config submodule.sub.url)" = subrepo
700 test_expect_success '../subrepo works with relative local path - foo/bar' '
702 cd reltest &&
703 cp pristine-.git-config .git/config &&
704 cp pristine-.gitmodules .gitmodules &&
705 git config remote.origin.url foo/bar &&
706 git submodule init &&
707 test "$(git config submodule.sub.url)" = foo/subrepo
711 test_expect_success '../subrepo works with relative local path - ./foo' '
713 cd reltest &&
714 cp pristine-.git-config .git/config &&
715 cp pristine-.gitmodules .gitmodules &&
716 git config remote.origin.url ./foo &&
717 git submodule init &&
718 test "$(git config submodule.sub.url)" = subrepo
722 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
724 cd reltest &&
725 cp pristine-.git-config .git/config &&
726 cp pristine-.gitmodules .gitmodules &&
727 git config remote.origin.url ./foo/bar &&
728 git submodule init &&
729 test "$(git config submodule.sub.url)" = foo/subrepo
733 test_expect_success '../subrepo works with relative local path - ../foo' '
735 cd reltest &&
736 cp pristine-.git-config .git/config &&
737 cp pristine-.gitmodules .gitmodules &&
738 git config remote.origin.url ../foo &&
739 git submodule init &&
740 test "$(git config submodule.sub.url)" = ../subrepo
744 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
746 cd reltest &&
747 cp pristine-.git-config .git/config &&
748 cp pristine-.gitmodules .gitmodules &&
749 git config remote.origin.url ../foo/bar &&
750 git submodule init &&
751 test "$(git config submodule.sub.url)" = ../foo/subrepo
755 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
757 cd reltest &&
758 cp pristine-.git-config .git/config &&
759 cp pristine-.gitmodules .gitmodules &&
760 mkdir -p a/b/c &&
761 (cd a/b/c; git init) &&
762 git config remote.origin.url ../foo/bar.git &&
763 git submodule add ../bar/a/b/c ./a/b/c &&
764 git submodule init &&
765 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
769 test_expect_success 'moving the superproject does not break submodules' '
771 cd addtest &&
772 git submodule status >expect
773 ) &&
774 mv addtest addtest2 &&
776 cd addtest2 &&
777 git submodule status >actual &&
778 test_cmp expect actual
782 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
784 cd addtest2 &&
786 cd repo &&
787 echo "$submodurl/repo" >expect &&
788 git config remote.origin.url >actual &&
789 test_cmp expect actual &&
790 echo "gitdir: ../.git/modules/repo" >expect &&
791 test_cmp expect .git
792 ) &&
793 rm -rf repo &&
794 git rm repo &&
795 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
796 test_must_be_empty actual &&
797 echo "gitdir: ../.git/modules/submod" >expect &&
798 test_cmp expect submod/.git &&
800 cd repo &&
801 echo "$submodurl/bare.git" >expect &&
802 git config remote.origin.url >actual &&
803 test_cmp expect actual &&
804 echo "gitdir: ../.git/modules/repo_new" >expect &&
805 test_cmp expect .git
806 ) &&
807 echo "repo" >expect &&
808 test_must_fail git config -f .gitmodules submodule.repo.path &&
809 git config -f .gitmodules submodule.repo_new.path >actual &&
810 test_cmp expect actual&&
811 echo "$submodurl/repo" >expect &&
812 test_must_fail git config -f .gitmodules submodule.repo.url &&
813 echo "$submodurl/bare.git" >expect &&
814 git config -f .gitmodules submodule.repo_new.url >actual &&
815 test_cmp expect actual &&
816 echo "$submodurl/repo" >expect &&
817 git config submodule.repo.url >actual &&
818 test_cmp expect actual &&
819 echo "$submodurl/bare.git" >expect &&
820 git config submodule.repo_new.url >actual &&
821 test_cmp expect actual
825 test_expect_success 'submodule add with an existing name fails unless forced' '
827 cd addtest2 &&
828 rm -rf repo &&
829 git rm repo &&
830 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
831 test ! -d repo &&
832 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
833 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
834 echo "$submodurl/bare.git" >expect &&
835 git config submodule.repo_new.url >actual &&
836 test_cmp expect actual &&
837 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
838 test -d repo &&
839 echo "repo" >expect &&
840 git config -f .gitmodules submodule.repo_new.path >actual &&
841 test_cmp expect actual&&
842 echo "$submodurl/repo.git" >expect &&
843 git config -f .gitmodules submodule.repo_new.url >actual &&
844 test_cmp expect actual &&
845 echo "$submodurl/repo.git" >expect &&
846 git config submodule.repo_new.url >actual &&
847 test_cmp expect actual
851 test_expect_success 'set up a second submodule' '
852 git submodule add ./init2 example2 &&
853 git commit -m "submodule example2 added"
856 test_expect_success 'submodule deinit works on repository without submodules' '
857 test_when_finished "rm -rf newdirectory" &&
858 mkdir newdirectory &&
860 cd newdirectory &&
861 git init &&
862 >file &&
863 git add file &&
864 git commit -m "repo should not be empty"
865 git submodule deinit . &&
866 git submodule deinit --all
870 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
871 git config submodule.example.foo bar &&
872 git config submodule.example2.frotz nitfol &&
873 git submodule deinit init &&
874 test -z "$(git config --get-regexp "submodule\.example\.")" &&
875 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
876 test -f example2/.git &&
877 rmdir init
880 test_expect_success 'submodule deinit from subdirectory' '
881 git submodule update --init &&
882 git config submodule.example.foo bar &&
883 mkdir -p sub &&
885 cd sub &&
886 git submodule deinit ../init >../output
887 ) &&
888 grep "\\.\\./init" output &&
889 test -z "$(git config --get-regexp "submodule\.example\.")" &&
890 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
891 test -f example2/.git &&
892 rmdir init
895 test_expect_success 'submodule deinit . deinits all initialized submodules' '
896 git submodule update --init &&
897 git config submodule.example.foo bar &&
898 git config submodule.example2.frotz nitfol &&
899 test_must_fail git submodule deinit &&
900 git submodule deinit . >actual &&
901 test -z "$(git config --get-regexp "submodule\.example\.")" &&
902 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
903 test_i18ngrep "Cleared directory .init" actual &&
904 test_i18ngrep "Cleared directory .example2" actual &&
905 rmdir init example2
908 test_expect_success 'submodule deinit --all deinits all initialized submodules' '
909 git submodule update --init &&
910 git config submodule.example.foo bar &&
911 git config submodule.example2.frotz nitfol &&
912 test_must_fail git submodule deinit &&
913 git submodule deinit --all >actual &&
914 test -z "$(git config --get-regexp "submodule\.example\.")" &&
915 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
916 test_i18ngrep "Cleared directory .init" actual &&
917 test_i18ngrep "Cleared directory .example2" actual &&
918 rmdir init example2
921 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
922 git submodule update --init &&
923 rm -rf init example2/* example2/.git &&
924 git submodule deinit init example2 >actual &&
925 test -z "$(git config --get-regexp "submodule\.example\.")" &&
926 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
927 test_i18ngrep ! "Cleared directory .init" actual &&
928 test_i18ngrep "Cleared directory .example2" actual &&
929 rmdir init
932 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
933 git submodule update --init &&
934 echo X >>init/s &&
935 test_must_fail git submodule deinit init &&
936 test -n "$(git config --get-regexp "submodule\.example\.")" &&
937 test -f example2/.git &&
938 git submodule deinit -f init >actual &&
939 test -z "$(git config --get-regexp "submodule\.example\.")" &&
940 test_i18ngrep "Cleared directory .init" actual &&
941 rmdir init
944 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
945 git submodule update --init &&
946 echo X >>init/untracked &&
947 test_must_fail git submodule deinit init &&
948 test -n "$(git config --get-regexp "submodule\.example\.")" &&
949 test -f example2/.git &&
950 git submodule deinit -f init >actual &&
951 test -z "$(git config --get-regexp "submodule\.example\.")" &&
952 test_i18ngrep "Cleared directory .init" actual &&
953 rmdir init
956 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
957 git submodule update --init &&
959 cd init &&
960 git checkout HEAD^
961 ) &&
962 test_must_fail git submodule deinit init &&
963 test -n "$(git config --get-regexp "submodule\.example\.")" &&
964 test -f example2/.git &&
965 git submodule deinit -f init >actual &&
966 test -z "$(git config --get-regexp "submodule\.example\.")" &&
967 test_i18ngrep "Cleared directory .init" actual &&
968 rmdir init
971 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
972 git submodule update --init &&
973 git submodule deinit init >actual &&
974 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
975 test_i18ngrep "Cleared directory .init" actual &&
976 git submodule deinit init >actual &&
977 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
978 test_i18ngrep "Cleared directory .init" actual &&
979 git submodule deinit . >actual &&
980 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
981 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
982 test_i18ngrep "Cleared directory .init" actual &&
983 git submodule deinit . >actual &&
984 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
985 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
986 test_i18ngrep "Cleared directory .init" actual &&
987 git submodule deinit --all >actual &&
988 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
989 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
990 test_i18ngrep "Cleared directory .init" actual &&
991 rmdir init example2
994 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
995 git submodule update --init &&
997 cd init &&
998 rm .git &&
999 cp -R ../.git/modules/example .git &&
1000 GIT_WORK_TREE=. git config --unset core.worktree
1001 ) &&
1002 test_must_fail git submodule deinit init &&
1003 test_must_fail git submodule deinit -f init &&
1004 test -d init/.git &&
1005 test -n "$(git config --get-regexp "submodule\.example\.")"
1008 test_expect_success 'submodule with UTF-8 name' '
1009 svname=$(printf "\303\245 \303\244\303\266") &&
1010 mkdir "$svname" &&
1012 cd "$svname" &&
1013 git init &&
1014 >sub &&
1015 git add sub &&
1016 git commit -m "init sub"
1017 ) &&
1018 git submodule add ./"$svname" &&
1019 git submodule >&2 &&
1020 test -n "$(git submodule | grep "$svname")"
1023 test_expect_success 'submodule add clone shallow submodule' '
1024 mkdir super &&
1025 pwd=$(pwd) &&
1027 cd super &&
1028 git init &&
1029 git submodule add --depth=1 file://"$pwd"/example2 submodule &&
1031 cd submodule &&
1032 test 1 = $(git log --oneline | wc -l)
1037 test_expect_success 'submodule helper list is not confused by common prefixes' '
1038 mkdir -p dir1/b &&
1040 cd dir1/b &&
1041 git init &&
1042 echo hi >testfile2 &&
1043 git add . &&
1044 git commit -m "test1"
1045 ) &&
1046 mkdir -p dir2/b &&
1048 cd dir2/b &&
1049 git init &&
1050 echo hello >testfile1 &&
1051 git add . &&
1052 git commit -m "test2"
1053 ) &&
1054 git submodule add /dir1/b dir1/b &&
1055 git submodule add /dir2/b dir2/b &&
1056 git commit -m "first submodule commit" &&
1057 git submodule--helper list dir1/b |cut -c51- >actual &&
1058 echo "dir1/b" >expect &&
1059 test_cmp expect actual
1063 test_done