Merge branch 'jc/topo-author-date-sort'
[git/jrn.git] / t / t7400-submodule-basic.sh
blob50e6ad7458c48842408e2afc20f84c117120c262
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_must_be_empty 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 subdirectory' '
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 'submodule add in subdirectory with relative path should fail' '
235 cd addtest/sub &&
236 test_must_fail git submodule add ../../ submod3 2>../../output.err
237 ) &&
238 test_i18ngrep toplevel output.err
241 test_expect_success 'setup - add an example entry to .gitmodules' '
242 GIT_CONFIG=.gitmodules \
243 git config submodule.example.url git://example.com/init.git
246 test_expect_success 'status should fail for unmapped paths' '
247 test_must_fail git submodule status
250 test_expect_success 'setup - map path in .gitmodules' '
251 cat <<\EOF >expect &&
252 [submodule "example"]
253 url = git://example.com/init.git
254 path = init
257 GIT_CONFIG=.gitmodules git config submodule.example.path init &&
259 test_cmp expect .gitmodules
262 test_expect_success 'status should only print one line' '
263 git submodule status >lines &&
264 test_line_count = 1 lines
267 test_expect_success 'setup - fetch commit name from submodule' '
268 rev1=$(cd .subrepo && git rev-parse HEAD) &&
269 printf "rev1: %s\n" "$rev1" &&
270 test -n "$rev1"
273 test_expect_success 'status should initially be "missing"' '
274 git submodule status >lines &&
275 grep "^-$rev1" lines
278 test_expect_success 'init should register submodule url in .git/config' '
279 echo git://example.com/init.git >expect &&
281 git submodule init &&
282 git config submodule.example.url >url &&
283 git config submodule.example.url ./.subrepo &&
285 test_cmp expect url
288 test_failure_with_unknown_submodule () {
289 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
290 grep "^error: .*no-such-submodule" output.err
293 test_expect_success 'init should fail with unknown submodule' '
294 test_failure_with_unknown_submodule init
297 test_expect_success 'update should fail with unknown submodule' '
298 test_failure_with_unknown_submodule update
301 test_expect_success 'status should fail with unknown submodule' '
302 test_failure_with_unknown_submodule status
305 test_expect_success 'sync should fail with unknown submodule' '
306 test_failure_with_unknown_submodule sync
309 test_expect_success 'update should fail when path is used by a file' '
310 echo hello >expect &&
312 echo "hello" >init &&
313 test_must_fail git submodule update &&
315 test_cmp expect init
318 test_expect_success 'update should fail when path is used by a nonempty directory' '
319 echo hello >expect &&
321 rm -fr init &&
322 mkdir init &&
323 echo "hello" >init/a &&
325 test_must_fail git submodule update &&
327 test_cmp expect init/a
330 test_expect_success 'update should work when path is an empty dir' '
331 rm -fr init &&
332 rm -f head-sha1 &&
333 echo "$rev1" >expect &&
335 mkdir init &&
336 git submodule update -q >update.out &&
337 test_must_be_empty update.out &&
339 inspect init &&
340 test_cmp expect head-sha1
343 test_expect_success 'status should be "up-to-date" after update' '
344 git submodule status >list &&
345 grep "^ $rev1" list
348 test_expect_success 'status "up-to-date" from subdirectory' '
349 mkdir -p sub &&
351 cd sub &&
352 git submodule status >../list
353 ) &&
354 grep "^ $rev1" list &&
355 grep "\\.\\./init" list
358 test_expect_success 'status "up-to-date" from subdirectory with path' '
359 mkdir -p sub &&
361 cd sub &&
362 git submodule status ../init >../list
363 ) &&
364 grep "^ $rev1" list &&
365 grep "\\.\\./init" list
368 test_expect_success 'status should be "modified" after submodule commit' '
370 cd init &&
371 echo b >b &&
372 git add b &&
373 git commit -m "submodule commit 2"
374 ) &&
376 rev2=$(cd init && git rev-parse HEAD) &&
377 test -n "$rev2" &&
378 git submodule status >list &&
380 grep "^+$rev2" list
383 test_expect_success 'the --cached sha1 should be rev1' '
384 git submodule --cached status >list &&
385 grep "^+$rev1" list
388 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
389 git diff >diff &&
390 grep "^+Subproject commit $rev2" diff
393 test_expect_success 'update should checkout rev1' '
394 rm -f head-sha1 &&
395 echo "$rev1" >expect &&
397 git submodule update init &&
398 inspect init &&
400 test_cmp expect head-sha1
403 test_expect_success 'status should be "up-to-date" after update' '
404 git submodule status >list &&
405 grep "^ $rev1" list
408 test_expect_success 'checkout superproject with subproject already present' '
409 git checkout initial &&
410 git checkout master
413 test_expect_success 'apply submodule diff' '
414 >empty &&
416 git branch second &&
418 cd init &&
419 echo s >s &&
420 git add s &&
421 git commit -m "change subproject"
422 ) &&
423 git update-index --add init &&
424 git commit -m "change init" &&
425 git format-patch -1 --stdout >P.diff &&
426 git checkout second &&
427 git apply --index P.diff &&
429 git diff --cached master >staged &&
430 test_cmp empty staged
433 test_expect_success 'update --init' '
434 mv init init2 &&
435 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
436 git config --remove-section submodule.example &&
437 test_must_fail git config submodule.example.url &&
439 git submodule update init > update.out &&
440 cat update.out &&
441 test_i18ngrep "not initialized" update.out &&
442 test_must_fail git rev-parse --resolve-git-dir init/.git &&
444 git submodule update --init init &&
445 git rev-parse --resolve-git-dir init/.git
448 test_expect_success 'update --init from subdirectory' '
449 mv init init2 &&
450 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
451 git config --remove-section submodule.example &&
452 test_must_fail git config submodule.example.url &&
454 mkdir -p sub &&
456 cd sub &&
457 git submodule update ../init >update.out &&
458 cat update.out &&
459 test_i18ngrep "not initialized" update.out &&
460 test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
462 git submodule update --init ../init
463 ) &&
464 git rev-parse --resolve-git-dir init/.git
467 test_expect_success 'do not add files from a submodule' '
469 git reset --hard &&
470 test_must_fail git add init/a
474 test_expect_success 'gracefully add submodule with a trailing slash' '
476 git reset --hard &&
477 git commit -m "commit subproject" init &&
478 (cd init &&
479 echo b > a) &&
480 git add init/ &&
481 git diff --exit-code --cached init &&
482 commit=$(cd init &&
483 git commit -m update a >/dev/null &&
484 git rev-parse HEAD) &&
485 git add init/ &&
486 test_must_fail git diff --exit-code --cached init &&
487 test $commit = $(git ls-files --stage |
488 sed -n "s/^160000 \([^ ]*\).*/\1/p")
492 test_expect_success 'ls-files gracefully handles trailing slash' '
494 test "init" = "$(git ls-files init/)"
498 test_expect_success 'moving to a commit without submodule does not leave empty dir' '
499 rm -rf init &&
500 mkdir init &&
501 git reset --hard &&
502 git checkout initial &&
503 test ! -d init &&
504 git checkout second
507 test_expect_success 'submodule <invalid-subcommand> fails' '
508 test_must_fail git submodule no-such-subcommand
511 test_expect_success 'add submodules without specifying an explicit path' '
512 mkdir repo &&
514 cd repo &&
515 git init &&
516 echo r >r &&
517 git add r &&
518 git commit -m "repo commit 1"
519 ) &&
520 git clone --bare repo/ bare.git &&
522 cd addtest &&
523 git submodule add "$submodurl/repo" &&
524 git config -f .gitmodules submodule.repo.path repo &&
525 git submodule add "$submodurl/bare.git" &&
526 git config -f .gitmodules submodule.bare.path bare
530 test_expect_success 'add should fail when path is used by a file' '
532 cd addtest &&
533 touch file &&
534 test_must_fail git submodule add "$submodurl/repo" file
538 test_expect_success 'add should fail when path is used by an existing directory' '
540 cd addtest &&
541 mkdir empty-dir &&
542 test_must_fail git submodule add "$submodurl/repo" empty-dir
546 test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
548 cd addtest &&
549 git submodule add ../repo relative &&
550 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
551 git submodule sync relative &&
552 test "$(git config submodule.relative.url)" = "$submodurl/repo"
556 test_expect_success 'set up for relative path tests' '
557 mkdir reltest &&
559 cd reltest &&
560 git init &&
561 mkdir sub &&
563 cd sub &&
564 git init &&
565 test_commit foo
566 ) &&
567 git add sub &&
568 git config -f .gitmodules submodule.sub.path sub &&
569 git config -f .gitmodules submodule.sub.url ../subrepo &&
570 cp .git/config pristine-.git-config &&
571 cp .gitmodules pristine-.gitmodules
575 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
577 cd reltest &&
578 cp pristine-.git-config .git/config &&
579 cp pristine-.gitmodules .gitmodules &&
580 git config remote.origin.url ssh://hostname/repo &&
581 git submodule init &&
582 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
586 test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
588 cd reltest &&
589 cp pristine-.git-config .git/config &&
590 cp pristine-.gitmodules .gitmodules &&
591 git config remote.origin.url ssh://hostname:22/repo &&
592 git submodule init &&
593 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
597 # About the choice of the path in the next test:
598 # - double-slash side-steps path mangling issues on Windows
599 # - it is still an absolute local path
600 # - there cannot be a server with a blank in its name just in case the
601 # path is used erroneously to access a //server/share style path
602 test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
604 cd reltest &&
605 cp pristine-.git-config .git/config &&
606 cp pristine-.gitmodules .gitmodules &&
607 git config remote.origin.url "//somewhere else/repo" &&
608 git submodule init &&
609 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
613 test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
615 cd reltest &&
616 cp pristine-.git-config .git/config &&
617 cp pristine-.gitmodules .gitmodules &&
618 git config remote.origin.url file:///tmp/repo &&
619 git submodule init &&
620 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
624 test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
626 cd reltest &&
627 cp pristine-.git-config .git/config &&
628 cp pristine-.gitmodules .gitmodules &&
629 git config remote.origin.url helper:://hostname/repo &&
630 git submodule init &&
631 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
635 test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
637 cd reltest &&
638 cp pristine-.git-config .git/config &&
639 git config remote.origin.url user@host:repo &&
640 git submodule init &&
641 test "$(git config submodule.sub.url)" = user@host:subrepo
645 test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
647 cd reltest &&
648 cp pristine-.git-config .git/config &&
649 cp pristine-.gitmodules .gitmodules &&
650 git config remote.origin.url user@host:path/to/repo &&
651 git submodule init &&
652 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
656 test_expect_success '../subrepo works with relative local path - foo' '
658 cd reltest &&
659 cp pristine-.git-config .git/config &&
660 cp pristine-.gitmodules .gitmodules &&
661 git config remote.origin.url foo &&
662 # actual: fails with an error
663 git submodule init &&
664 test "$(git config submodule.sub.url)" = subrepo
668 test_expect_success '../subrepo works with relative local path - foo/bar' '
670 cd reltest &&
671 cp pristine-.git-config .git/config &&
672 cp pristine-.gitmodules .gitmodules &&
673 git config remote.origin.url foo/bar &&
674 git submodule init &&
675 test "$(git config submodule.sub.url)" = foo/subrepo
679 test_expect_success '../subrepo works with relative local path - ./foo' '
681 cd reltest &&
682 cp pristine-.git-config .git/config &&
683 cp pristine-.gitmodules .gitmodules &&
684 git config remote.origin.url ./foo &&
685 git submodule init &&
686 test "$(git config submodule.sub.url)" = subrepo
690 test_expect_success '../subrepo works with relative local path - ./foo/bar' '
692 cd reltest &&
693 cp pristine-.git-config .git/config &&
694 cp pristine-.gitmodules .gitmodules &&
695 git config remote.origin.url ./foo/bar &&
696 git submodule init &&
697 test "$(git config submodule.sub.url)" = foo/subrepo
701 test_expect_success '../subrepo works with relative local path - ../foo' '
703 cd reltest &&
704 cp pristine-.git-config .git/config &&
705 cp pristine-.gitmodules .gitmodules &&
706 git config remote.origin.url ../foo &&
707 git submodule init &&
708 test "$(git config submodule.sub.url)" = ../subrepo
712 test_expect_success '../subrepo works with relative local path - ../foo/bar' '
714 cd reltest &&
715 cp pristine-.git-config .git/config &&
716 cp pristine-.gitmodules .gitmodules &&
717 git config remote.origin.url ../foo/bar &&
718 git submodule init &&
719 test "$(git config submodule.sub.url)" = ../foo/subrepo
723 test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
725 cd reltest &&
726 cp pristine-.git-config .git/config &&
727 cp pristine-.gitmodules .gitmodules &&
728 mkdir -p a/b/c &&
729 (cd a/b/c; git init) &&
730 git config remote.origin.url ../foo/bar.git &&
731 git submodule add ../bar/a/b/c ./a/b/c &&
732 git submodule init &&
733 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
737 test_expect_success 'moving the superproject does not break submodules' '
739 cd addtest &&
740 git submodule status >expect
742 mv addtest addtest2 &&
744 cd addtest2 &&
745 git submodule status >actual &&
746 test_cmp expect actual
750 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
752 cd addtest2 &&
754 cd repo &&
755 echo "$submodurl/repo" >expect &&
756 git config remote.origin.url >actual &&
757 test_cmp expect actual &&
758 echo "gitdir: ../.git/modules/repo" >expect &&
759 test_cmp expect .git
760 ) &&
761 rm -rf repo &&
762 git rm repo &&
763 git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
764 test_must_be_empty actual &&
765 echo "gitdir: ../.git/modules/submod" >expect &&
766 test_cmp expect submod/.git &&
768 cd repo &&
769 echo "$submodurl/bare.git" >expect &&
770 git config remote.origin.url >actual &&
771 test_cmp expect actual &&
772 echo "gitdir: ../.git/modules/repo_new" >expect &&
773 test_cmp expect .git
774 ) &&
775 echo "repo" >expect &&
776 git config -f .gitmodules submodule.repo.path >actual &&
777 test_cmp expect actual &&
778 git config -f .gitmodules submodule.repo_new.path >actual &&
779 test_cmp expect actual&&
780 echo "$submodurl/repo" >expect &&
781 git config -f .gitmodules submodule.repo.url >actual &&
782 test_cmp expect actual &&
783 echo "$submodurl/bare.git" >expect &&
784 git config -f .gitmodules submodule.repo_new.url >actual &&
785 test_cmp expect actual &&
786 echo "$submodurl/repo" >expect &&
787 git config submodule.repo.url >actual &&
788 test_cmp expect actual &&
789 echo "$submodurl/bare.git" >expect &&
790 git config submodule.repo_new.url >actual &&
791 test_cmp expect actual
795 test_expect_success 'submodule add with an existing name fails unless forced' '
797 cd addtest2 &&
798 rm -rf repo &&
799 git rm repo &&
800 test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo &&
801 test ! -d repo &&
802 echo "repo" >expect &&
803 git config -f .gitmodules submodule.repo_new.path >actual &&
804 test_cmp expect actual&&
805 echo "$submodurl/bare.git" >expect &&
806 git config -f .gitmodules submodule.repo_new.url >actual &&
807 test_cmp expect actual &&
808 echo "$submodurl/bare.git" >expect &&
809 git config submodule.repo_new.url >actual &&
810 test_cmp expect actual &&
811 git submodule add -f -q --name repo_new "$submodurl/repo.git" repo &&
812 test -d repo &&
813 echo "repo" >expect &&
814 git config -f .gitmodules submodule.repo_new.path >actual &&
815 test_cmp expect actual&&
816 echo "$submodurl/repo.git" >expect &&
817 git config -f .gitmodules submodule.repo_new.url >actual &&
818 test_cmp expect actual &&
819 echo "$submodurl/repo.git" >expect &&
820 git config submodule.repo_new.url >actual &&
821 test_cmp expect actual
825 test_expect_success 'set up a second submodule' '
826 git submodule add ./init2 example2 &&
827 git commit -m "submodule example2 added"
830 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
831 git config submodule.example.foo bar &&
832 git config submodule.example2.frotz nitfol &&
833 git submodule deinit init &&
834 test -z "$(git config --get-regexp "submodule\.example\.")" &&
835 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
836 test -f example2/.git &&
837 rmdir init
840 test_expect_success 'submodule deinit from subdirectory' '
841 git submodule update --init &&
842 git config submodule.example.foo bar &&
843 mkdir -p sub &&
845 cd sub &&
846 git submodule deinit ../init >../output
847 ) &&
848 grep "\\.\\./init" output &&
849 test -z "$(git config --get-regexp "submodule\.example\.")" &&
850 test -n "$(git config --get-regexp "submodule\.example2\.")" &&
851 test -f example2/.git &&
852 rmdir init
855 test_expect_success 'submodule deinit . deinits all initialized submodules' '
856 git submodule update --init &&
857 git config submodule.example.foo bar &&
858 git config submodule.example2.frotz nitfol &&
859 test_must_fail git submodule deinit &&
860 git submodule deinit . >actual &&
861 test -z "$(git config --get-regexp "submodule\.example\.")" &&
862 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
863 test_i18ngrep "Cleared directory .init" actual &&
864 test_i18ngrep "Cleared directory .example2" actual &&
865 rmdir init example2
868 test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
869 git submodule update --init &&
870 rm -rf init example2/* example2/.git &&
871 git submodule deinit init example2 >actual &&
872 test -z "$(git config --get-regexp "submodule\.example\.")" &&
873 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
874 test_i18ngrep ! "Cleared directory .init" actual &&
875 test_i18ngrep "Cleared directory .example2" actual &&
876 rmdir init
879 test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
880 git submodule update --init &&
881 echo X >>init/s &&
882 test_must_fail git submodule deinit init &&
883 test -n "$(git config --get-regexp "submodule\.example\.")" &&
884 test -f example2/.git &&
885 git submodule deinit -f init >actual &&
886 test -z "$(git config --get-regexp "submodule\.example\.")" &&
887 test_i18ngrep "Cleared directory .init" actual &&
888 rmdir init
891 test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
892 git submodule update --init &&
893 echo X >>init/untracked &&
894 test_must_fail git submodule deinit init &&
895 test -n "$(git config --get-regexp "submodule\.example\.")" &&
896 test -f example2/.git &&
897 git submodule deinit -f init >actual &&
898 test -z "$(git config --get-regexp "submodule\.example\.")" &&
899 test_i18ngrep "Cleared directory .init" actual &&
900 rmdir init
903 test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
904 git submodule update --init &&
906 cd init &&
907 git checkout HEAD^
908 ) &&
909 test_must_fail git submodule deinit init &&
910 test -n "$(git config --get-regexp "submodule\.example\.")" &&
911 test -f example2/.git &&
912 git submodule deinit -f init >actual &&
913 test -z "$(git config --get-regexp "submodule\.example\.")" &&
914 test_i18ngrep "Cleared directory .init" actual &&
915 rmdir init
918 test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
919 git submodule update --init &&
920 git submodule deinit init >actual &&
921 test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
922 test_i18ngrep "Cleared directory .init" actual &&
923 git submodule deinit init >actual &&
924 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
925 test_i18ngrep "Cleared directory .init" actual &&
926 git submodule deinit . >actual &&
927 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
928 test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
929 test_i18ngrep "Cleared directory .init" actual &&
930 git submodule deinit . >actual &&
931 test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
932 test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
933 test_i18ngrep "Cleared directory .init" actual &&
934 rmdir init example2
937 test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
938 git submodule update --init &&
940 cd init &&
941 rm .git &&
942 cp -R ../.git/modules/example .git &&
943 GIT_WORK_TREE=. git config --unset core.worktree
944 ) &&
945 test_must_fail git submodule deinit init &&
946 test_must_fail git submodule deinit -f init &&
947 test -d init/.git &&
948 test -n "$(git config --get-regexp "submodule\.example\.")"
951 test_expect_success 'submodule with UTF-8 name' '
952 svname=$(printf "\303\245 \303\244\303\266") &&
953 mkdir "$svname" &&
955 cd "$svname" &&
956 git init &&
957 >sub &&
958 git add sub &&
959 git commit -m "init sub"
960 ) &&
961 test_config core.precomposeunicode true &&
962 git submodule add ./"$svname" &&
963 git submodule >&2 &&
964 test -n "$(git submodule | grep "$svname")"
966 test_done