Merge branch 'fc/remote-hg' into next
[git/mjg.git] / t / t7400-submodule-basic.sh
blobeb9bf77a5b8f0c4b3bfc6e3d9dcdd281b81fdc19
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 'setup - initial commit' '
15 >t &&
16 git add t &&
17 git commit -m "initial commit" &&
18 git branch initial
21 test_expect_success 'setup - repository in init subdirectory' '
22 mkdir init &&
24 cd init &&
25 git init &&
26 echo a >a &&
27 git add a &&
28 git commit -m "submodule commit 1" &&
29 git tag -a -m "rev-1" rev-1
33 test_expect_success 'setup - commit with gitlink' '
34 echo a >a &&
35 echo z >z &&
36 git add a init z &&
37 git commit -m "super commit 1"
40 test_expect_success 'setup - hide init subdirectory' '
41 mv init .subrepo
44 test_expect_success 'setup - repository to add submodules to' '
45 git init addtest &&
46 git init addtest-ignore
49 # The 'submodule add' tests need some repository to add as a submodule.
50 # The trash directory is a good one as any. We need to canonicalize
51 # the name, though, as some tests compare it to the absolute path git
52 # generates, which will expand symbolic links.
53 submodurl=$(pwd -P)
55 listbranches() {
56 git for-each-ref --format='%(refname)' 'refs/heads/*'
59 inspect() {
60 dir=$1 &&
61 dotdot="${2:-..}" &&
64 cd "$dir" &&
65 listbranches >"$dotdot/heads" &&
66 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
67 git rev-parse HEAD >"$dotdot/head-sha1" &&
68 git update-index --refresh &&
69 git diff-files --exit-code &&
70 git clean -n -d -x >"$dotdot/untracked"
74 test_expect_success 'submodule add' '
75 echo "refs/heads/master" >expect &&
76 >empty &&
79 cd addtest &&
80 git submodule add -q "$submodurl" submod >actual &&
81 test ! -s actual &&
82 echo "gitdir: ../.git/modules/submod" >expect &&
83 test_cmp expect submod/.git &&
85 cd submod &&
86 git config core.worktree >actual &&
87 echo "../../../submod" >expect &&
88 test_cmp expect actual &&
89 rm -f actual expect
90 ) &&
91 git submodule init
92 ) &&
94 rm -f heads head untracked &&
95 inspect addtest/submod ../.. &&
96 test_cmp expect heads &&
97 test_cmp expect head &&
98 test_cmp empty untracked
101 test_expect_success 'submodule add to .gitignored path fails' '
103 cd addtest-ignore &&
104 cat <<-\EOF >expect &&
105 The following path is ignored by one of your .gitignore files:
106 submod
107 Use -f if you really want to add it.
109 # Does not use test_commit due to the ignore
110 echo "*" > .gitignore &&
111 git add --force .gitignore &&
112 git commit -m"Ignore everything" &&
113 ! git submodule add "$submodurl" submod >actual 2>&1 &&
114 test_i18ncmp expect actual
118 test_expect_success 'submodule add to .gitignored path with --force' '
120 cd addtest-ignore &&
121 git submodule add --force "$submodurl" submod
125 test_expect_success 'submodule add --branch' '
126 echo "refs/heads/initial" >expect-head &&
127 cat <<-\EOF >expect-heads &&
128 refs/heads/initial
129 refs/heads/master
131 >empty &&
134 cd addtest &&
135 git submodule add -b initial "$submodurl" submod-branch &&
136 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
137 git submodule init
138 ) &&
140 rm -f heads head untracked &&
141 inspect addtest/submod-branch ../.. &&
142 test_cmp expect-heads heads &&
143 test_cmp expect-head head &&
144 test_cmp empty untracked
147 test_expect_success 'submodule add with ./ in path' '
148 echo "refs/heads/master" >expect &&
149 >empty &&
152 cd addtest &&
153 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
154 git submodule init
155 ) &&
157 rm -f heads head untracked &&
158 inspect addtest/dotsubmod/frotz ../../.. &&
159 test_cmp expect heads &&
160 test_cmp expect head &&
161 test_cmp empty untracked
164 test_expect_success 'submodule add with // in path' '
165 echo "refs/heads/master" >expect &&
166 >empty &&
169 cd addtest &&
170 git submodule add "$submodurl" slashslashsubmod///frotz// &&
171 git submodule init
172 ) &&
174 rm -f heads head untracked &&
175 inspect addtest/slashslashsubmod/frotz ../../.. &&
176 test_cmp expect heads &&
177 test_cmp expect head &&
178 test_cmp empty untracked
181 test_expect_success 'submodule add with /.. in path' '
182 echo "refs/heads/master" >expect &&
183 >empty &&
186 cd addtest &&
187 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
188 git submodule init
189 ) &&
191 rm -f heads head untracked &&
192 inspect addtest/realsubmod ../.. &&
193 test_cmp expect heads &&
194 test_cmp expect head &&
195 test_cmp empty untracked
198 test_expect_success 'submodule add with ./, /.. and // in path' '
199 echo "refs/heads/master" >expect &&
200 >empty &&
203 cd addtest &&
204 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
205 git submodule init
206 ) &&
208 rm -f heads head untracked &&
209 inspect addtest/realsubmod2 ../.. &&
210 test_cmp expect heads &&
211 test_cmp expect head &&
212 test_cmp empty untracked
215 test_expect_success 'submodule add in subdir' '
216 echo "refs/heads/master" >expect &&
217 >empty &&
219 mkdir addtest/sub &&
221 cd addtest/sub &&
222 git submodule add "$submodurl" ../realsubmod3 &&
223 git submodule init
224 ) &&
226 rm -f heads head untracked &&
227 inspect addtest/realsubmod3 ../.. &&
228 test_cmp expect heads &&
229 test_cmp expect head &&
230 test_cmp empty untracked
233 test_expect_success 'setup - add an example entry to .gitmodules' '
234 GIT_CONFIG=.gitmodules \
235 git config submodule.example.url git://example.com/init.git
238 test_expect_success 'status should fail for unmapped paths' '
239 test_must_fail git submodule status
242 test_expect_success 'setup - map path in .gitmodules' '
243 cat <<\EOF >expect &&
244 [submodule "example"]
245 url = git://example.com/init.git
246 path = init
249 GIT_CONFIG=.gitmodules git config submodule.example.path init &&
251 test_cmp expect .gitmodules
254 test_expect_success 'status should only print one line' '
255 git submodule status >lines &&
256 test_line_count = 1 lines
259 test_expect_success 'setup - fetch commit name from submodule' '
260 rev1=$(cd .subrepo && git rev-parse HEAD) &&
261 printf "rev1: %s\n" "$rev1" &&
262 test -n "$rev1"
265 test_expect_success 'status should initially be "missing"' '
266 git submodule status >lines &&
267 grep "^-$rev1" lines
270 test_expect_success 'init should register submodule url in .git/config' '
271 echo git://example.com/init.git >expect &&
273 git submodule init &&
274 git config submodule.example.url >url &&
275 git config submodule.example.url ./.subrepo &&
277 test_cmp expect url
280 test_failure_with_unknown_submodule () {
281 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
282 grep "^error: .*no-such-submodule" output.err
285 test_expect_success 'init should fail with unknown submodule' '
286 test_failure_with_unknown_submodule init
289 test_expect_success 'update should fail with unknown submodule' '
290 test_failure_with_unknown_submodule update
293 test_expect_success 'status should fail with unknown submodule' '
294 test_failure_with_unknown_submodule status
297 test_expect_success 'sync should fail with unknown submodule' '
298 test_failure_with_unknown_submodule sync
301 test_expect_success 'update should fail when path is used by a file' '
302 echo hello >expect &&
304 echo "hello" >init &&
305 test_must_fail git submodule update &&
307 test_cmp expect init
310 test_expect_success 'update should fail when path is used by a nonempty directory' '
311 echo hello >expect &&
313 rm -fr init &&
314 mkdir init &&
315 echo "hello" >init/a &&
317 test_must_fail git submodule update &&
319 test_cmp expect init/a
322 test_expect_success 'update should work when path is an empty dir' '
323 rm -fr init &&
324 rm -f head-sha1 &&
325 echo "$rev1" >expect &&
327 mkdir init &&
328 git submodule update -q >update.out &&
329 test ! -s update.out &&
331 inspect init &&
332 test_cmp expect head-sha1
335 test_expect_success 'status should be "up-to-date" after update' '
336 git submodule status >list &&
337 grep "^ $rev1" list
340 test_expect_success 'status works correctly from a subdirectory' '
341 mkdir sub &&
343 cd sub &&
344 git submodule status >../list
345 ) &&
346 grep "^ $rev1" list
349 test_expect_success 'status should be "modified" after submodule commit' '
351 cd init &&
352 echo b >b &&
353 git add b &&
354 git commit -m "submodule commit 2"
355 ) &&
357 rev2=$(cd init && git rev-parse HEAD) &&
358 test -n "$rev2" &&
359 git submodule status >list &&
361 grep "^+$rev2" list
364 test_expect_success 'the --cached sha1 should be rev1' '
365 git submodule --cached status >list &&
366 grep "^+$rev1" list
369 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
370 git diff >diff &&
371 grep "^+Subproject commit $rev2" diff
374 test_expect_success 'update should checkout rev1' '
375 rm -f head-sha1 &&
376 echo "$rev1" >expect &&
378 git submodule update init &&
379 inspect init &&
381 test_cmp expect head-sha1
384 test_expect_success 'status should be "up-to-date" after update' '
385 git submodule status >list &&
386 grep "^ $rev1" list
389 test_expect_success 'checkout superproject with subproject already present' '
390 git checkout initial &&
391 git checkout master
394 test_expect_success 'apply submodule diff' '
395 >empty &&
397 git branch second &&
399 cd init &&
400 echo s >s &&
401 git add s &&
402 git commit -m "change subproject"
403 ) &&
404 git update-index --add init &&
405 git commit -m "change init" &&
406 git format-patch -1 --stdout >P.diff &&
407 git checkout second &&
408 git apply --index P.diff &&
410 git diff --cached master >staged &&
411 test_cmp empty staged
414 test_expect_success 'update --init' '
415 mv init init2 &&
416 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
417 git config --remove-section submodule.example &&
418 test_must_fail git config submodule.example.url &&
420 git submodule update init > update.out &&
421 cat update.out &&
422 test_i18ngrep "not initialized" update.out &&
423 test_must_fail git rev-parse --resolve-git-dir init/.git &&
425 git submodule update --init init &&
426 git rev-parse --resolve-git-dir init/.git
429 test_expect_success 'do not add files from a submodule' '
431 git reset --hard &&
432 test_must_fail git add init/a
436 test_expect_success 'gracefully add submodule with a trailing slash' '
438 git reset --hard &&
439 git commit -m "commit subproject" init &&
440 (cd init &&
441 echo b > a) &&
442 git add init/ &&
443 git diff --exit-code --cached init &&
444 commit=$(cd init &&
445 git commit -m update a >/dev/null &&
446 git rev-parse HEAD) &&
447 git add init/ &&
448 test_must_fail git diff --exit-code --cached init &&
449 test $commit = $(git ls-files --stage |
450 sed -n "s/^160000 \([^ ]*\).*/\1/p")
454 test_expect_success 'ls-files gracefully handles trailing slash' '
456 test "init" = "$(git ls-files init/)"
460 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
461 rm -rf init &&
462 mkdir init &&
463 git reset --hard &&
464 git checkout initial &&
465 test ! -d init &&
466 git checkout second
469 test_expect_success 'submodule <invalid-subcommand> fails' '
470 test_must_fail git submodule no-such-subcommand
473 test_expect_success 'add submodules without specifying an explicit path' '
474 mkdir repo &&
476 cd repo &&
477 git init &&
478 echo r >r &&
479 git add r &&
480 git commit -m "repo commit 1"
481 ) &&
482 git clone --bare repo/ bare.git &&
484 cd addtest &&
485 git submodule add "$submodurl/repo" &&
486 git config -f .gitmodules submodule.repo.path repo &&
487 git submodule add "$submodurl/bare.git" &&
488 git config -f .gitmodules submodule.bare.path bare
492 test_expect_success 'add should fail when path is used by a file' '
494 cd addtest &&
495 touch file &&
496 test_must_fail git submodule add "$submodurl/repo" file
500 test_expect_success 'add should fail when path is used by an existing directory' '
502 cd addtest &&
503 mkdir empty-dir &&
504 test_must_fail git submodule add "$submodurl/repo" empty-dir
508 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
510 cd addtest &&
511 git submodule add ../repo relative &&
512 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
513 git submodule sync relative &&
514 test "$(git config submodule.relative.url)" = "$submodurl/repo"
518 test_expect_success 'set up for relative path tests' '
519 mkdir reltest &&
521 cd reltest &&
522 git init &&
523 mkdir sub &&
525 cd sub &&
526 git init &&
527 test_commit foo
528 ) &&
529 git add sub &&
530 git config -f .gitmodules submodule.sub.path sub &&
531 git config -f .gitmodules submodule.sub.url ../subrepo &&
532 cp .git/config pristine-.git-config &&
533 cp .gitmodules pristine-.gitmodules
537 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
539 cd reltest &&
540 cp pristine-.git-config .git/config &&
541 cp pristine-.gitmodules .gitmodules &&
542 git config remote.origin.url ssh://hostname/repo &&
543 git submodule init &&
544 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
548 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
550 cd reltest &&
551 cp pristine-.git-config .git/config &&
552 cp pristine-.gitmodules .gitmodules &&
553 git config remote.origin.url ssh://hostname:22/repo &&
554 git submodule init &&
555 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
559 # About the choice of the path in the next test:
560 # - double-slash side-steps path mangling issues on Windows
561 # - it is still an absolute local path
562 # - there cannot be a server with a blank in its name just in case the
563 # path is used erroneously to access a //server/share style path
564 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
566 cd reltest &&
567 cp pristine-.git-config .git/config &&
568 cp pristine-.gitmodules .gitmodules &&
569 git config remote.origin.url "//somewhere else/repo" &&
570 git submodule init &&
571 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
575 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
577 cd reltest &&
578 cp pristine-.git-config .git/config &&
579 cp pristine-.gitmodules .gitmodules &&
580 git config remote.origin.url file:///tmp/repo &&
581 git submodule init &&
582 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
586 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
588 cd reltest &&
589 cp pristine-.git-config .git/config &&
590 cp pristine-.gitmodules .gitmodules &&
591 git config remote.origin.url helper:://hostname/repo &&
592 git submodule init &&
593 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
597 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
599 cd reltest &&
600 cp pristine-.git-config .git/config &&
601 git config remote.origin.url user@host:repo &&
602 git submodule init &&
603 test "$(git config submodule.sub.url)" = user@host:subrepo
607 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
609 cd reltest &&
610 cp pristine-.git-config .git/config &&
611 cp pristine-.gitmodules .gitmodules &&
612 git config remote.origin.url user@host:path/to/repo &&
613 git submodule init &&
614 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
618 test_expect_success '../subrepo works with relative local path - foo' '
620 cd reltest &&
621 cp pristine-.git-config .git/config &&
622 cp pristine-.gitmodules .gitmodules &&
623 git config remote.origin.url foo &&
624 # actual: fails with an error
625 git submodule init &&
626 test "$(git config submodule.sub.url)" = subrepo
630 test_expect_success '../subrepo works with relative local path - foo/bar' '
632 cd reltest &&
633 cp pristine-.git-config .git/config &&
634 cp pristine-.gitmodules .gitmodules &&
635 git config remote.origin.url foo/bar &&
636 git submodule init &&
637 test "$(git config submodule.sub.url)" = foo/subrepo
641 test_expect_success '../subrepo works with relative local path - ./foo' '
643 cd reltest &&
644 cp pristine-.git-config .git/config &&
645 cp pristine-.gitmodules .gitmodules &&
646 git config remote.origin.url ./foo &&
647 git submodule init &&
648 test "$(git config submodule.sub.url)" = subrepo
652 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
654 cd reltest &&
655 cp pristine-.git-config .git/config &&
656 cp pristine-.gitmodules .gitmodules &&
657 git config remote.origin.url ./foo/bar &&
658 git submodule init &&
659 test "$(git config submodule.sub.url)" = foo/subrepo
663 test_expect_success '../subrepo works with relative local path - ../foo' '
665 cd reltest &&
666 cp pristine-.git-config .git/config &&
667 cp pristine-.gitmodules .gitmodules &&
668 git config remote.origin.url ../foo &&
669 git submodule init &&
670 test "$(git config submodule.sub.url)" = ../subrepo
674 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
676 cd reltest &&
677 cp pristine-.git-config .git/config &&
678 cp pristine-.gitmodules .gitmodules &&
679 git config remote.origin.url ../foo/bar &&
680 git submodule init &&
681 test "$(git config submodule.sub.url)" = ../foo/subrepo
685 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
687 cd reltest &&
688 cp pristine-.git-config .git/config &&
689 cp pristine-.gitmodules .gitmodules &&
690 mkdir -p a/b/c &&
691 (cd a/b/c; git init) &&
692 git config remote.origin.url ../foo/bar.git &&
693 git submodule add ../bar/a/b/c ./a/b/c &&
694 git submodule init &&
695 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
699 test_expect_success 'moving the superproject does not break submodules' '
701 cd addtest &&
702 git submodule status >expect
704 mv addtest addtest2 &&
706 cd addtest2 &&
707 git submodule status >actual &&
708 test_cmp expect actual
712 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
714 cd addtest2 &&
716 cd repo &&
717 echo "$submodurl/repo" >expect &&
718 git config remote.origin.url >actual &&
719 test_cmp expect actual &&
720 echo "gitdir: ../.git/modules/repo" >expect &&
721 test_cmp expect .git
722 ) &&
723 rm -rf repo &&
724 git rm repo &&
725 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
726 test ! -s actual &&
727 echo "gitdir: ../.git/modules/submod" >expect &&
728 test_cmp expect submod/.git &&
730 cd repo &&
731 echo "$submodurl/bare.git" >expect &&
732 git config remote.origin.url >actual &&
733 test_cmp expect actual &&
734 echo "gitdir: ../.git/modules/repo_new" >expect &&
735 test_cmp expect .git
736 ) &&
737 echo "repo" >expect &&
738 test_must_fail git config -f .gitmodules submodule.repo.path &&
739 git config -f .gitmodules submodule.repo_new.path >actual &&
740 test_cmp expect actual&&
741 echo "$submodurl/repo" >expect &&
742 test_must_fail git config -f .gitmodules submodule.repo.url &&
743 echo "$submodurl/bare.git" >expect &&
744 git config -f .gitmodules submodule.repo_new.url >actual &&
745 test_cmp expect actual &&
746 echo "$submodurl/repo" >expect &&
747 git config submodule.repo.url >actual &&
748 test_cmp expect actual &&
749 echo "$submodurl/bare.git" >expect &&
750 git config submodule.repo_new.url >actual &&
751 test_cmp expect actual
755 test_expect_success 'submodule add with an existing name fails unless forced' '
757 cd addtest2 &&
758 rm -rf repo &&
759 git rm repo &&
760 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
761 test ! -d repo &&
762 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
763 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
764 echo "$submodurl/bare.git" >expect &&
765 git config submodule.repo_new.url >actual &&
766 test_cmp expect actual &&
767 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
768 test -d repo &&
769 echo "repo" >expect &&
770 git config -f .gitmodules submodule.repo_new.path >actual &&
771 test_cmp expect actual&&
772 echo "$submodurl/repo.git" >expect &&
773 git config -f .gitmodules submodule.repo_new.url >actual &&
774 test_cmp expect actual &&
775 echo "$submodurl/repo.git" >expect &&
776 git config submodule.repo_new.url >actual &&
777 test_cmp expect actual
781 test_expect_success 'set up a second submodule' '
782 git submodule add ./init2 example2 &&
783 git commit -m "submodule example2 added"
786 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
787 git config submodule.example.foo bar &&
788 git config submodule.example2.frotz nitfol &&
789 git submodule deinit init &&
790 test -z "$(git config --get-regexp "submodule\.example\.")" &&
791 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
792 test -f example2/.git &&
793 rmdir init
796 test_expect_success 'submodule deinit . deinits all initialized submodules' '
797 git submodule update --init &&
798 git config submodule.example.foo bar &&
799 git config submodule.example2.frotz nitfol &&
800 test_must_fail git submodule deinit &&
801 git submodule deinit . >actual &&
802 test -z "$(git config --get-regexp "submodule\.example\.")" &&
803 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
804 test_i18ngrep "Cleared directory .init" actual &&
805 test_i18ngrep "Cleared directory .example2" actual &&
806 rmdir init example2
809 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
810 git submodule update --init &&
811 rm -rf init example2/* example2/.git &&
812 git submodule deinit init example2 >actual &&
813 test -z "$(git config --get-regexp "submodule\.example\.")" &&
814 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
815 test_i18ngrep ! "Cleared directory .init" actual &&
816 test_i18ngrep "Cleared directory .example2" actual &&
817 rmdir init
820 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
821 git submodule update --init &&
822 echo X >>init/s &&
823 test_must_fail git submodule deinit init &&
824 test -n "$(git config --get-regexp "submodule\.example\.")" &&
825 test -f example2/.git &&
826 git submodule deinit -f init >actual &&
827 test -z "$(git config --get-regexp "submodule\.example\.")" &&
828 test_i18ngrep "Cleared directory .init" actual &&
829 rmdir init
832 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
833 git submodule update --init &&
834 echo X >>init/untracked &&
835 test_must_fail git submodule deinit init &&
836 test -n "$(git config --get-regexp "submodule\.example\.")" &&
837 test -f example2/.git &&
838 git submodule deinit -f init >actual &&
839 test -z "$(git config --get-regexp "submodule\.example\.")" &&
840 test_i18ngrep "Cleared directory .init" actual &&
841 rmdir init
844 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
845 git submodule update --init &&
847 cd init &&
848 git checkout HEAD^
849 ) &&
850 test_must_fail git submodule deinit init &&
851 test -n "$(git config --get-regexp "submodule\.example\.")" &&
852 test -f example2/.git &&
853 git submodule deinit -f init >actual &&
854 test -z "$(git config --get-regexp "submodule\.example\.")" &&
855 test_i18ngrep "Cleared directory .init" actual &&
856 rmdir init
859 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
860 git submodule update --init &&
861 git submodule deinit init >actual &&
862 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
863 test_i18ngrep "Cleared directory .init" actual &&
864 git submodule deinit init >actual &&
865 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
866 test_i18ngrep "Cleared directory .init" actual &&
867 git submodule deinit . >actual &&
868 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
869 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
870 test_i18ngrep "Cleared directory .init" actual &&
871 git submodule deinit . >actual &&
872 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
873 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
874 test_i18ngrep "Cleared directory .init" actual &&
875 rmdir init example2
878 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
879 git submodule update --init &&
881 cd init &&
882 rm .git &&
883 cp -R ../.git/modules/example .git &&
884 GIT_WORK_TREE=. git config --unset core.worktree
885 ) &&
886 test_must_fail git submodule deinit init &&
887 test_must_fail git submodule deinit -f init &&
888 test -d init/.git &&
889 test -n "$(git config --get-regexp "submodule\.example\.")"
892 test_done