#!/bin/sh # # Copyright (c) 2007 Lars Hjemli # global test_description := ''Basic porcelain support for submodules This test tries to verify basic sanity of the init, update and status subcommands of git submodule. '' source ./test-lib.sh test_expect_success 'submodule deinit works on empty repository' ' git submodule deinit --all ' test_expect_success 'setup - initial commit' ' >t && git add t && git commit -m "initial commit" && git branch initial ' test_expect_success 'submodule init aborts on missing .gitmodules file' ' test_when_finished "git update-index --remove sub" && git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && # missing the .gitmodules file here test_must_fail git submodule init 2>actual && test_i18ngrep "No url found for submodule path" actual ' test_expect_success 'submodule update aborts on missing .gitmodules file' ' test_when_finished "git update-index --remove sub" && git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && # missing the .gitmodules file here git submodule update sub 2>actual && test_i18ngrep "Submodule path .sub. not initialized" actual ' test_expect_success 'configuration parsing' ' test_when_finished "rm -f .gitmodules" && cat >.gitmodules <<-\EOF && [submodule "s"] path ignore EOF test_must_fail git status ' test_expect_success 'setup - repository in init subdirectory' ' mkdir init && ( cd init && git init && echo a >a && git add a && git commit -m "submodule commit 1" && git tag -a -m "rev-1" rev-1 ) ' test_expect_success 'setup - commit with gitlink' ' echo a >a && echo z >z && git add a init z && git commit -m "super commit 1" ' test_expect_success 'setup - hide init subdirectory' ' mv init .subrepo ' test_expect_success 'setup - repository to add submodules to' ' git init addtest && git init addtest-ignore ' # The 'submodule add' tests need some repository to add as a submodule. # The trash directory is a good one as any. We need to canonicalize # the name, though, as some tests compare it to the absolute path git # generates, which will expand symbolic links. global submodurl := $[pwd -P] proc listbranches { git for-each-ref --format='%(refname)' 'refs/heads/*' } proc inspect { global dir := $1 && global dotdot := $(2:-..) && shell { cd $dir && listbranches >"$dotdot/heads" && do { git symbolic-ref HEAD || :; } >"$dotdot/head" && git rev-parse HEAD >"$dotdot/head-sha1" && git update-index --refresh && git diff-files --exit-code && git clean -n -d -x >"$dotdot/untracked" } } test_expect_success 'submodule add' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add -q "$submodurl" submod >actual && test_must_be_empty actual && echo "gitdir: ../.git/modules/submod" >expect && test_cmp expect submod/.git && ( cd submod && git config core.worktree >actual && echo "../../../submod" >expect && test_cmp expect actual && rm -f actual expect ) && git submodule init ) && rm -f heads head untracked && inspect addtest/submod ../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add to .gitignored path fails' ' ( cd addtest-ignore && cat <<-\EOF >expect && The following path is ignored by one of your .gitignore files: submod Use -f if you really want to add it. EOF # Does not use test_commit due to the ignore echo "*" > .gitignore && git add --force .gitignore && git commit -m"Ignore everything" && ! git submodule add "$submodurl" submod >actual 2>&1 && test_i18ncmp expect actual ) ' test_expect_success 'submodule add to .gitignored path with --force' ' ( cd addtest-ignore && git submodule add --force "$submodurl" submod ) ' test_expect_success 'submodule add --branch' ' echo "refs/heads/initial" >expect-head && cat <<-\EOF >expect-heads && refs/heads/initial refs/heads/master EOF >empty && ( cd addtest && git submodule add -b initial "$submodurl" submod-branch && test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" && git submodule init ) && rm -f heads head untracked && inspect addtest/submod-branch ../.. && test_cmp expect-heads heads && test_cmp expect-head head && test_cmp empty untracked ' test_expect_success 'submodule add with ./ in path' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add "$submodurl" ././dotsubmod/./frotz/./ && git submodule init ) && rm -f heads head untracked && inspect addtest/dotsubmod/frotz ../../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add with /././ in path' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ && git submodule init ) && rm -f heads head untracked && inspect addtest/dotslashdotsubmod/frotz ../../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add with // in path' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add "$submodurl" slashslashsubmod///frotz// && git submodule init ) && rm -f heads head untracked && inspect addtest/slashslashsubmod/frotz ../../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add with /.. in path' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && git submodule init ) && rm -f heads head untracked && inspect addtest/realsubmod ../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add with ./, /.. and // in path' ' echo "refs/heads/master" >expect && >empty && ( cd addtest && git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && git submodule init ) && rm -f heads head untracked && inspect addtest/realsubmod2 ../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add in subdirectory' ' echo "refs/heads/master" >expect && >empty && mkdir addtest/sub && ( cd addtest/sub && git submodule add "$submodurl" ../realsubmod3 && git submodule init ) && rm -f heads head untracked && inspect addtest/realsubmod3 ../.. && test_cmp expect heads && test_cmp expect head && test_cmp empty untracked ' test_expect_success 'submodule add in subdirectory with relative path should fail' ' ( cd addtest/sub && test_must_fail git submodule add ../../ submod3 2>../../output.err ) && test_i18ngrep toplevel output.err ' test_expect_success 'setup - add an example entry to .gitmodules' ' git config --file=.gitmodules submodule.example.url git://example.com/init.git ' test_expect_success 'status should fail for unmapped paths' ' test_must_fail git submodule status ' test_expect_success 'setup - map path in .gitmodules' ' cat <<\EOF >expect && [submodule "example"] url = git://example.com/init.git path = init EOF git config --file=.gitmodules submodule.example.path init && test_cmp expect .gitmodules ' test_expect_success 'status should only print one line' ' git submodule status >lines && test_line_count = 1 lines ' test_expect_success 'setup - fetch commit name from submodule' ' rev1=$(cd .subrepo && git rev-parse HEAD) && printf "rev1: %s\n" "$rev1" && test -n "$rev1" ' test_expect_success 'status should initially be "missing"' ' git submodule status >lines && grep "^-$rev1" lines ' test_expect_success 'init should register submodule url in .git/config' ' echo git://example.com/init.git >expect && git submodule init && git config submodule.example.url >url && git config submodule.example.url ./.subrepo && test_cmp expect url ' proc test_failure_with_unknown_submodule { test_must_fail git submodule $1 no-such-submodule !2 >output.err && grep "^error: .*no-such-submodule" output.err } test_expect_success 'init should fail with unknown submodule' ' test_failure_with_unknown_submodule init ' test_expect_success 'update should fail with unknown submodule' ' test_failure_with_unknown_submodule update ' test_expect_success 'status should fail with unknown submodule' ' test_failure_with_unknown_submodule status ' test_expect_success 'sync should fail with unknown submodule' ' test_failure_with_unknown_submodule sync ' test_expect_success 'update should fail when path is used by a file' ' echo hello >expect && echo "hello" >init && test_must_fail git submodule update && test_cmp expect init ' test_expect_success 'update should fail when path is used by a nonempty directory' ' echo hello >expect && rm -fr init && mkdir init && echo "hello" >init/a && test_must_fail git submodule update && test_cmp expect init/a ' test_expect_success 'update should work when path is an empty dir' ' rm -fr init && rm -f head-sha1 && echo "$rev1" >expect && mkdir init && git submodule update -q >update.out && test_must_be_empty update.out && inspect init && test_cmp expect head-sha1 ' test_expect_success 'status should be "up-to-date" after update' ' git submodule status >list && grep "^ $rev1" list ' test_expect_success 'status "up-to-date" from subdirectory' ' mkdir -p sub && ( cd sub && git submodule status >../list ) && grep "^ $rev1" list && grep "\\.\\./init" list ' test_expect_success 'status "up-to-date" from subdirectory with path' ' mkdir -p sub && ( cd sub && git submodule status ../init >../list ) && grep "^ $rev1" list && grep "\\.\\./init" list ' test_expect_success 'status should be "modified" after submodule commit' ' ( cd init && echo b >b && git add b && git commit -m "submodule commit 2" ) && rev2=$(cd init && git rev-parse HEAD) && test -n "$rev2" && git submodule status >list && grep "^+$rev2" list ' test_expect_success 'the --cached sha1 should be rev1' ' git submodule --cached status >list && grep "^+$rev1" list ' test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' git diff >diff && grep "^+Subproject commit $rev2" diff ' test_expect_success 'update should checkout rev1' ' rm -f head-sha1 && echo "$rev1" >expect && git submodule update init && inspect init && test_cmp expect head-sha1 ' test_expect_success 'status should be "up-to-date" after update' ' git submodule status >list && grep "^ $rev1" list ' test_expect_success 'checkout superproject with subproject already present' ' git checkout initial && git checkout master ' test_expect_success 'apply submodule diff' ' >empty && git branch second && ( cd init && echo s >s && git add s && git commit -m "change subproject" ) && git update-index --add init && git commit -m "change init" && git format-patch -1 --stdout >P.diff && git checkout second && git apply --index P.diff && git diff --cached master >staged && test_cmp empty staged ' test_expect_success 'update --init' ' mv init init2 && git config -f .gitmodules submodule.example.url "$(pwd)/init2" && git config --remove-section submodule.example && test_must_fail git config submodule.example.url && git submodule update init 2> update.out && cat update.out && test_i18ngrep "not initialized" update.out && test_must_fail git rev-parse --resolve-git-dir init/.git && git submodule update --init init && git rev-parse --resolve-git-dir init/.git ' test_expect_success 'update --init from subdirectory' ' mv init init2 && git config -f .gitmodules submodule.example.url "$(pwd)/init2" && git config --remove-section submodule.example && test_must_fail git config submodule.example.url && mkdir -p sub && ( cd sub && git submodule update ../init 2>update.out && cat update.out && test_i18ngrep "not initialized" update.out && test_must_fail git rev-parse --resolve-git-dir ../init/.git && git submodule update --init ../init ) && git rev-parse --resolve-git-dir init/.git ' test_expect_success 'do not add files from a submodule' ' git reset --hard && test_must_fail git add init/a ' test_expect_success 'gracefully add/reset submodule with a trailing slash' ' git reset --hard && git commit -m "commit subproject" init && (cd init && echo b > a) && git add init/ && git diff --exit-code --cached init && commit=$(cd init && git commit -m update a >/dev/null && git rev-parse HEAD) && git add init/ && test_must_fail git diff --exit-code --cached init && test $commit = $(git ls-files --stage | sed -n "s/^160000 \([^ ]*\).*/\1/p") && git reset init/ && git diff --exit-code --cached init ' test_expect_success 'ls-files gracefully handles trailing slash' ' test "init" = "$(git ls-files init/)" ' test_expect_success 'moving to a commit without submodule does not leave empty dir' ' rm -rf init && mkdir init && git reset --hard && git checkout initial && test ! -d init && git checkout second ' test_expect_success 'submodule fails' ' test_must_fail git submodule no-such-subcommand ' test_expect_success 'add submodules without specifying an explicit path' ' mkdir repo && ( cd repo && git init && echo r >r && git add r && git commit -m "repo commit 1" ) && git clone --bare repo/ bare.git && ( cd addtest && git submodule add "$submodurl/repo" && git config -f .gitmodules submodule.repo.path repo && git submodule add "$submodurl/bare.git" && git config -f .gitmodules submodule.bare.path bare ) ' test_expect_success 'add should fail when path is used by a file' ' ( cd addtest && touch file && test_must_fail git submodule add "$submodurl/repo" file ) ' test_expect_success 'add should fail when path is used by an existing directory' ' ( cd addtest && mkdir empty-dir && test_must_fail git submodule add "$submodurl/repo" empty-dir ) ' test_expect_success 'use superproject as upstream when path is relative and no url is set there' ' ( cd addtest && git submodule add ../repo relative && test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && git submodule sync relative && test "$(git config submodule.relative.url)" = "$submodurl/repo" ) ' test_expect_success 'set up for relative path tests' ' mkdir reltest && ( cd reltest && git init && mkdir sub && ( cd sub && git init && test_commit foo ) && git add sub && git config -f .gitmodules submodule.sub.path sub && git config -f .gitmodules submodule.sub.url ../subrepo && cp .git/config pristine-.git-config && cp .gitmodules pristine-.gitmodules ) ' test_expect_success '../subrepo works with URL - ssh://hostname/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ssh://hostname/repo && git submodule init && test "$(git config submodule.sub.url)" = ssh://hostname/subrepo ) ' test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ssh://hostname:22/repo && git submodule init && test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo ) ' # About the choice of the path in the next test: # - double-slash side-steps path mangling issues on Windows # - it is still an absolute local path # - there cannot be a server with a blank in its name just in case the # path is used erroneously to access a //server/share style path test_expect_success '../subrepo path works with local path - //somewhere else/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url "//somewhere else/repo" && git submodule init && test "$(git config submodule.sub.url)" = "//somewhere else/subrepo" ) ' test_expect_success '../subrepo works with file URL - file:///tmp/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url file:///tmp/repo && git submodule init && test "$(git config submodule.sub.url)" = file:///tmp/subrepo ) ' test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url helper:://hostname/repo && git submodule init && test "$(git config submodule.sub.url)" = helper:://hostname/subrepo ) ' test_expect_success '../subrepo works with scp-style URL - user@host:repo' ' ( cd reltest && cp pristine-.git-config .git/config && git config remote.origin.url user@host:repo && git submodule init && test "$(git config submodule.sub.url)" = user@host:subrepo ) ' test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url user@host:path/to/repo && git submodule init && test "$(git config submodule.sub.url)" = user@host:path/to/subrepo ) ' test_expect_success '../subrepo works with relative local path - foo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url foo && # actual: fails with an error git submodule init && test "$(git config submodule.sub.url)" = subrepo ) ' test_expect_success '../subrepo works with relative local path - foo/bar' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url foo/bar && git submodule init && test "$(git config submodule.sub.url)" = foo/subrepo ) ' test_expect_success '../subrepo works with relative local path - ./foo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ./foo && git submodule init && test "$(git config submodule.sub.url)" = subrepo ) ' test_expect_success '../subrepo works with relative local path - ./foo/bar' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ./foo/bar && git submodule init && test "$(git config submodule.sub.url)" = foo/subrepo ) ' test_expect_success '../subrepo works with relative local path - ../foo' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ../foo && git submodule init && test "$(git config submodule.sub.url)" = ../subrepo ) ' test_expect_success '../subrepo works with relative local path - ../foo/bar' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && git config remote.origin.url ../foo/bar && git submodule init && test "$(git config submodule.sub.url)" = ../foo/subrepo ) ' test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' ' ( cd reltest && cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && mkdir -p a/b/c && (cd a/b/c; git init) && git config remote.origin.url ../foo/bar.git && git submodule add ../bar/a/b/c ./a/b/c && git submodule init && test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c ) ' test_expect_success 'moving the superproject does not break submodules' ' ( cd addtest && git submodule status >expect ) && mv addtest addtest2 && ( cd addtest2 && git submodule status >actual && test_cmp expect actual ) ' test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' ' ( cd addtest2 && ( cd repo && echo "$submodurl/repo" >expect && git config remote.origin.url >actual && test_cmp expect actual && echo "gitdir: ../.git/modules/repo" >expect && test_cmp expect .git ) && rm -rf repo && git rm repo && git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual && test_must_be_empty actual && echo "gitdir: ../.git/modules/submod" >expect && test_cmp expect submod/.git && ( cd repo && echo "$submodurl/bare.git" >expect && git config remote.origin.url >actual && test_cmp expect actual && echo "gitdir: ../.git/modules/repo_new" >expect && test_cmp expect .git ) && echo "repo" >expect && test_must_fail git config -f .gitmodules submodule.repo.path && git config -f .gitmodules submodule.repo_new.path >actual && test_cmp expect actual&& echo "$submodurl/repo" >expect && test_must_fail git config -f .gitmodules submodule.repo.url && echo "$submodurl/bare.git" >expect && git config -f .gitmodules submodule.repo_new.url >actual && test_cmp expect actual && echo "$submodurl/repo" >expect && git config submodule.repo.url >actual && test_cmp expect actual && echo "$submodurl/bare.git" >expect && git config submodule.repo_new.url >actual && test_cmp expect actual ) ' test_expect_success 'recursive relative submodules stay relative' ' test_when_finished "rm -rf super clone2 subsub sub3" && mkdir subsub && ( cd subsub && git init && >t && git add t && git commit -m "initial commit" ) && mkdir sub3 && ( cd sub3 && git init && >t && git add t && git commit -m "initial commit" && git submodule add ../subsub dirdir/subsub && git commit -m "add submodule subsub" ) && mkdir super && ( cd super && git init && >t && git add t && git commit -m "initial commit" && git submodule add ../sub3 && git commit -m "add submodule sub" ) && git clone super clone2 && ( cd clone2 && git submodule update --init --recursive && echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect && echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect ) && test_cmp clone2/sub3/.git_expect clone2/sub3/.git && test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git ' test_expect_success 'submodule add with an existing name fails unless forced' ' ( cd addtest2 && rm -rf repo && git rm repo && test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && test ! -d repo && test_must_fail git config -f .gitmodules submodule.repo_new.path && test_must_fail git config -f .gitmodules submodule.repo_new.url && echo "$submodurl/bare.git" >expect && git config submodule.repo_new.url >actual && test_cmp expect actual && git submodule add -f -q --name repo_new "$submodurl/repo.git" repo && test -d repo && echo "repo" >expect && git config -f .gitmodules submodule.repo_new.path >actual && test_cmp expect actual&& echo "$submodurl/repo.git" >expect && git config -f .gitmodules submodule.repo_new.url >actual && test_cmp expect actual && echo "$submodurl/repo.git" >expect && git config submodule.repo_new.url >actual && test_cmp expect actual ) ' test_expect_success 'set up a second submodule' ' git submodule add ./init2 example2 && git commit -m "submodule example2 added" ' test_expect_success 'submodule deinit works on repository without submodules' ' test_when_finished "rm -rf newdirectory" && mkdir newdirectory && ( cd newdirectory && git init && >file && git add file && git commit -m "repo should not be empty" && git submodule deinit . && git submodule deinit --all ) ' test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && git submodule deinit init && test -z "$(git config --get-regexp "submodule\.example\.")" && test -n "$(git config --get-regexp "submodule\.example2\.")" && test -f example2/.git && rmdir init ' test_expect_success 'submodule deinit from subdirectory' ' git submodule update --init && git config submodule.example.foo bar && mkdir -p sub && ( cd sub && git submodule deinit ../init >../output ) && test_i18ngrep "\\.\\./init" output && test -z "$(git config --get-regexp "submodule\.example\.")" && test -n "$(git config --get-regexp "submodule\.example2\.")" && test -f example2/.git && rmdir init ' test_expect_success 'submodule deinit . deinits all initialized submodules' ' git submodule update --init && git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && test_must_fail git submodule deinit && git submodule deinit . >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep "Cleared directory .init" actual && test_i18ngrep "Cleared directory .example2" actual && rmdir init example2 ' test_expect_success 'submodule deinit --all deinits all initialized submodules' ' git submodule update --init && git config submodule.example.foo bar && git config submodule.example2.frotz nitfol && test_must_fail git submodule deinit && git submodule deinit --all >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep "Cleared directory .init" actual && test_i18ngrep "Cleared directory .example2" actual && rmdir init example2 ' test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' git submodule update --init && rm -rf init example2/* example2/.git && git submodule deinit init example2 >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example2\.")" && test_i18ngrep ! "Cleared directory .init" actual && test_i18ngrep "Cleared directory .example2" actual && rmdir init ' test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' ' git submodule update --init && echo X >>init/s && test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && git submodule deinit -f init >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init ' test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' ' git submodule update --init && echo X >>init/untracked && test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && git submodule deinit -f init >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init ' test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' ' git submodule update --init && ( cd init && git checkout HEAD^ ) && test_must_fail git submodule deinit init && test -n "$(git config --get-regexp "submodule\.example\.")" && test -f example2/.git && git submodule deinit -f init >actual && test -z "$(git config --get-regexp "submodule\.example\.")" && test_i18ngrep "Cleared directory .init" actual && rmdir init ' test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' git submodule update --init && git submodule deinit init >actual && test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && git submodule deinit init >actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Cleared directory .init" actual && git submodule deinit . >actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual && git submodule deinit . >actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual && git submodule deinit --all >actual && test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && test_i18ngrep "Cleared directory .init" actual && rmdir init example2 ' test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' git submodule update --init && ( cd init && rm .git && cp -R ../.git/modules/example .git && GIT_WORK_TREE=. git config --unset core.worktree ) && test_must_fail git submodule deinit init && test_must_fail git submodule deinit -f init && test -d init/.git && test -n "$(git config --get-regexp "submodule\.example\.")" ' test_expect_success 'submodule with UTF-8 name' ' svname=$(printf "\303\245 \303\244\303\266") && mkdir "$svname" && ( cd "$svname" && git init && >sub && git add sub && git commit -m "init sub" ) && git submodule add ./"$svname" && git submodule >&2 && test -n "$(git submodule | grep "$svname")" ' test_expect_success 'submodule add clone shallow submodule' ' mkdir super && pwd=$(pwd) && ( cd super && git init && git submodule add --depth=1 file://"$pwd"/example2 submodule && ( cd submodule && test 1 = $(git log --oneline | wc -l) ) ) ' test_expect_success 'submodule helper list is not confused by common prefixes' ' mkdir -p dir1/b && ( cd dir1/b && git init && echo hi >testfile2 && git add . && git commit -m "test1" ) && mkdir -p dir2/b && ( cd dir2/b && git init && echo hello >testfile1 && git add . && git commit -m "test2" ) && git submodule add /dir1/b dir1/b && git submodule add /dir2/b dir2/b && git commit -m "first submodule commit" && git submodule--helper list dir1/b |cut -c51- >actual && echo "dir1/b" >expect && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"Basic porcelain support for submodules\n"> <"\n"> <"This test tries to verify basic sanity of the init, update and status\n"> <"subcommands of git submodule.\n"> ) } spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"submodule deinit works on empty repository">)} {(SQ <"\n"> <"\tgit submodule deinit --all\n">)} ) (C {(test_expect_success)} {(SQ <"setup - initial commit">)} { (SQ <"\n"> <"\t>t &&\n"> <"\tgit add t &&\n"> <"\tgit commit -m \"initial commit\" &&\n"> <"\tgit branch initial\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule init aborts on missing .gitmodules file">)} { (SQ <"\n"> <"\ttest_when_finished \"git update-index --remove sub\" &&\n"> <"\tgit update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&\n"> <"\t# missing the .gitmodules file here\n"> <"\ttest_must_fail git submodule init 2>actual &&\n"> <"\ttest_i18ngrep \"No url found for submodule path\" actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule update aborts on missing .gitmodules file">)} { (SQ <"\n"> <"\ttest_when_finished \"git update-index --remove sub\" &&\n"> <"\tgit update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&\n"> <"\t# missing the .gitmodules file here\n"> <"\tgit submodule update sub 2>actual &&\n"> <"\ttest_i18ngrep \"Submodule path .sub. not initialized\" actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"configuration parsing">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -f .gitmodules\" &&\n"> <"\tcat >.gitmodules <<-\\EOF &&\n"> <"\t[submodule \"s\"]\n"> <"\t\tpath\n"> <"\t\tignore\n"> <"\tEOF\n"> <"\ttest_must_fail git status\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup - repository in init subdirectory">)} { (SQ <"\n"> <"\tmkdir init &&\n"> <"\t(\n"> <"\t\tcd init &&\n"> <"\t\tgit init &&\n"> <"\t\techo a >a &&\n"> <"\t\tgit add a &&\n"> <"\t\tgit commit -m \"submodule commit 1\" &&\n"> <"\t\tgit tag -a -m \"rev-1\" rev-1\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup - commit with gitlink">)} { (SQ <"\n"> <"\techo a >a &&\n"> <"\techo z >z &&\n"> <"\tgit add a init z &&\n"> <"\tgit commit -m \"super commit 1\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup - hide init subdirectory">)} {(SQ <"\n"> <"\tmv init .subrepo\n">)} ) (C {(test_expect_success)} {(SQ <"setup - repository to add submodules to">)} {(SQ <"\n"> <"\tgit init addtest &&\n"> <"\tgit init addtest-ignore\n">)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:submodurl) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)} {(-P)})]) left_token: spids: [177 181] ) } spids: [176] ) ] spids: [176] ) (FuncDef name: listbranches body: (BraceGroup children: [ (C {(git)} {(for-each-ref)} {(--format) (Lit_Other "=") (SQ <"%(refname)">)} {(SQ <"refs/heads/*">)} ) ] spids: [188] ) spids: [184 187] ) (FuncDef name: inspect body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: {($ VSub_Number "$1")} spids: [215] ) ] spids: [215] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dotdot) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(..)}) spids: [223 227] ) ) } spids: [221] ) ] spids: [221] ) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Name "$dir"))}) (AndOr children: [ (SimpleCommand words: [{(listbranches)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$dotdot") (/heads))} spids: [248] ) ] ) (AndOr children: [ (BraceGroup children: [ (Sentence child: (AndOr children: [ (C {(git)} {(symbolic-ref)} {(HEAD)}) (C {(Lit_Other ":")}) ] op_id: Op_DPipe ) terminator: ) ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$dotdot") (/head))} spids: [272] ) ] spids: [257] ) (AndOr children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(HEAD)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$dotdot") (/head-sha1))} spids: [287] ) ] ) (AndOr children: [ (C {(git)} {(update-index)} {(--refresh)}) (AndOr children: [ (C {(git)} {(diff-files)} {(--exit-code)}) (SimpleCommand words: [{(git)} {(clean)} {(-n)} {(-d)} {(-x)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$dotdot") (/untracked))} spids: [324] ) ] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [234 331] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [212] ) spids: [208 211] ) (C {(test_expect_success)} {(SQ <"submodule add">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add -q \"$submodurl\" submod >actual &&\n"> <"\t\ttest_must_be_empty actual &&\n"> <"\t\techo \"gitdir: ../.git/modules/submod\" >expect &&\n"> <"\t\ttest_cmp expect submod/.git &&\n"> <"\t\t(\n"> <"\t\t\tcd submod &&\n"> <"\t\t\tgit config core.worktree >actual &&\n"> <"\t\t\techo \"../../../submod\" >expect &&\n"> <"\t\t\ttest_cmp expect actual &&\n"> <"\t\t\trm -f actual expect\n"> <"\t\t) &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/submod ../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add to .gitignored path fails">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest-ignore &&\n"> <"\t\tcat <<-\\EOF >expect &&\n"> <"\t\tThe following path is ignored by one of your .gitignore files:\n"> <"\t\tsubmod\n"> <"\t\tUse -f if you really want to add it.\n"> <"\t\tEOF\n"> <"\t\t# Does not use test_commit due to the ignore\n"> <"\t\techo \"*\" > .gitignore &&\n"> <"\t\tgit add --force .gitignore &&\n"> <"\t\tgit commit -m\"Ignore everything\" &&\n"> <"\t\t! git submodule add \"$submodurl\" submod >actual 2>&1 &&\n"> <"\t\ttest_i18ncmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add to .gitignored path with --force">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest-ignore &&\n"> <"\t\tgit submodule add --force \"$submodurl\" submod\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add --branch">)} { (SQ <"\n"> <"\techo \"refs/heads/initial\" >expect-head &&\n"> <"\tcat <<-\\EOF >expect-heads &&\n"> <"\trefs/heads/initial\n"> <"\trefs/heads/master\n"> <"\tEOF\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add -b initial \"$submodurl\" submod-branch &&\n"> < "\t\ttest \"initial\" = \"$(git config -f .gitmodules submodule.submod-branch.branch)\" &&\n" > <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/submod-branch ../.. &&\n"> <"\ttest_cmp expect-heads heads &&\n"> <"\ttest_cmp expect-head head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with ./ in path">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add \"$submodurl\" ././dotsubmod/./frotz/./ &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/dotsubmod/frotz ../../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with /././ in path">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add \"$submodurl\" dotslashdotsubmod/././frotz/./ &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/dotslashdotsubmod/frotz ../../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with // in path">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add \"$submodurl\" slashslashsubmod///frotz// &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/slashslashsubmod/frotz ../../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with /.. in path">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add \"$submodurl\" dotdotsubmod/../realsubmod/frotz/.. &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/realsubmod ../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with ./, /.. and // in path">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> < "\t\tgit submodule add \"$submodurl\" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&\n" > <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/realsubmod2 ../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add in subdirectory">)} { (SQ <"\n"> <"\techo \"refs/heads/master\" >expect &&\n"> <"\t>empty &&\n"> <"\n"> <"\tmkdir addtest/sub &&\n"> <"\t(\n"> <"\t\tcd addtest/sub &&\n"> <"\t\tgit submodule add \"$submodurl\" ../realsubmod3 &&\n"> <"\t\tgit submodule init\n"> <"\t) &&\n"> <"\n"> <"\trm -f heads head untracked &&\n"> <"\tinspect addtest/realsubmod3 ../.. &&\n"> <"\ttest_cmp expect heads &&\n"> <"\ttest_cmp expect head &&\n"> <"\ttest_cmp empty untracked\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add in subdirectory with relative path should fail">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest/sub &&\n"> <"\t\ttest_must_fail git submodule add ../../ submod3 2>../../output.err\n"> <"\t) &&\n"> <"\ttest_i18ngrep toplevel output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup - add an example entry to .gitmodules">)} { (SQ <"\n"> <"\tgit config --file=.gitmodules submodule.example.url git://example.com/init.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should fail for unmapped paths">)} {(SQ <"\n"> <"\ttest_must_fail git submodule status\n">)} ) (C {(test_expect_success)} {(SQ <"setup - map path in .gitmodules">)} { (SQ <"\n"> <"\tcat <<\\EOF >expect &&\n"> <"[submodule \"example\"]\n"> <"\turl = git://example.com/init.git\n"> <"\tpath = init\n"> <"EOF\n"> <"\n"> <"\tgit config --file=.gitmodules submodule.example.path init &&\n"> <"\n"> <"\ttest_cmp expect .gitmodules\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should only print one line">)} {(SQ <"\n"> <"\tgit submodule status >lines &&\n"> <"\ttest_line_count = 1 lines\n">)} ) (C {(test_expect_success)} {(SQ <"setup - fetch commit name from submodule">)} { (SQ <"\n"> <"\trev1=$(cd .subrepo && git rev-parse HEAD) &&\n"> <"\tprintf \"rev1: %s\\n\" \"$rev1\" &&\n"> <"\ttest -n \"$rev1\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should initially be \"missing\"">)} {(SQ <"\n"> <"\tgit submodule status >lines &&\n"> <"\tgrep \"^-$rev1\" lines\n">)} ) (C {(test_expect_success)} {(SQ <"init should register submodule url in .git/config">)} { (SQ <"\n"> <"\techo git://example.com/init.git >expect &&\n"> <"\n"> <"\tgit submodule init &&\n"> <"\tgit config submodule.example.url >url &&\n"> <"\tgit config submodule.example.url ./.subrepo &&\n"> <"\n"> <"\ttest_cmp expect url\n"> ) } ) (FuncDef name: test_failure_with_unknown_submodule body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [ {(test_must_fail)} {(git)} {(submodule)} {($ VSub_Number "$1")} {(no-such-submodule)} ] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(output.err)} spids:[728])] ) (C {(grep)} {(DQ ("^error: .*no-such-submodule"))} {(output.err)}) ] op_id: Op_DAmp ) ] spids: [715] ) spids: [710 714] ) (C {(test_expect_success)} {(SQ <"init should fail with unknown submodule">)} {(SQ <"\n"> <"\ttest_failure_with_unknown_submodule init\n">)} ) (C {(test_expect_success)} {(SQ <"update should fail with unknown submodule">)} {(SQ <"\n"> <"\ttest_failure_with_unknown_submodule update\n">)} ) (C {(test_expect_success)} {(SQ <"status should fail with unknown submodule">)} {(SQ <"\n"> <"\ttest_failure_with_unknown_submodule status\n">)} ) (C {(test_expect_success)} {(SQ <"sync should fail with unknown submodule">)} {(SQ <"\n"> <"\ttest_failure_with_unknown_submodule sync\n">)} ) (C {(test_expect_success)} {(SQ <"update should fail when path is used by a file">)} { (SQ <"\n"> <"\techo hello >expect &&\n"> <"\n"> <"\techo \"hello\" >init &&\n"> <"\ttest_must_fail git submodule update &&\n"> <"\n"> <"\ttest_cmp expect init\n"> ) } ) (C {(test_expect_success)} {(SQ <"update should fail when path is used by a nonempty directory">)} { (SQ <"\n"> <"\techo hello >expect &&\n"> <"\n"> <"\trm -fr init &&\n"> <"\tmkdir init &&\n"> <"\techo \"hello\" >init/a &&\n"> <"\n"> <"\ttest_must_fail git submodule update &&\n"> <"\n"> <"\ttest_cmp expect init/a\n"> ) } ) (C {(test_expect_success)} {(SQ <"update should work when path is an empty dir">)} { (SQ <"\n"> <"\trm -fr init &&\n"> <"\trm -f head-sha1 &&\n"> <"\techo \"$rev1\" >expect &&\n"> <"\n"> <"\tmkdir init &&\n"> <"\tgit submodule update -q >update.out &&\n"> <"\ttest_must_be_empty update.out &&\n"> <"\n"> <"\tinspect init &&\n"> <"\ttest_cmp expect head-sha1\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should be \"up-to-date\" after update">)} {(SQ <"\n"> <"\tgit submodule status >list &&\n"> <"\tgrep \"^ $rev1\" list\n">)} ) (C {(test_expect_success)} {(SQ <"status \"up-to-date\" from subdirectory">)} { (SQ <"\n"> <"\tmkdir -p sub &&\n"> <"\t(\n"> <"\t\tcd sub &&\n"> <"\t\tgit submodule status >../list\n"> <"\t) &&\n"> <"\tgrep \"^ $rev1\" list &&\n"> <"\tgrep \"\\\\.\\\\./init\" list\n"> ) } ) (C {(test_expect_success)} {(SQ <"status \"up-to-date\" from subdirectory with path">)} { (SQ <"\n"> <"\tmkdir -p sub &&\n"> <"\t(\n"> <"\t\tcd sub &&\n"> <"\t\tgit submodule status ../init >../list\n"> <"\t) &&\n"> <"\tgrep \"^ $rev1\" list &&\n"> <"\tgrep \"\\\\.\\\\./init\" list\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should be \"modified\" after submodule commit">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd init &&\n"> <"\t\techo b >b &&\n"> <"\t\tgit add b &&\n"> <"\t\tgit commit -m \"submodule commit 2\"\n"> <"\t) &&\n"> <"\n"> <"\trev2=$(cd init && git rev-parse HEAD) &&\n"> <"\ttest -n \"$rev2\" &&\n"> <"\tgit submodule status >list &&\n"> <"\n"> <"\tgrep \"^+$rev2\" list\n"> ) } ) (C {(test_expect_success)} {(SQ <"the --cached sha1 should be rev1">)} {(SQ <"\n"> <"\tgit submodule --cached status >list &&\n"> <"\tgrep \"^+$rev1\" list\n">)} ) (C {(test_expect_success)} {(SQ <"git diff should report the SHA1 of the new submodule commit">)} {(SQ <"\n"> <"\tgit diff >diff &&\n"> <"\tgrep \"^+Subproject commit $rev2\" diff\n">)} ) (C {(test_expect_success)} {(SQ <"update should checkout rev1">)} { (SQ <"\n"> <"\trm -f head-sha1 &&\n"> <"\techo \"$rev1\" >expect &&\n"> <"\n"> <"\tgit submodule update init &&\n"> <"\tinspect init &&\n"> <"\n"> <"\ttest_cmp expect head-sha1\n"> ) } ) (C {(test_expect_success)} {(SQ <"status should be \"up-to-date\" after update">)} {(SQ <"\n"> <"\tgit submodule status >list &&\n"> <"\tgrep \"^ $rev1\" list\n">)} ) (C {(test_expect_success)} {(SQ <"checkout superproject with subproject already present">)} {(SQ <"\n"> <"\tgit checkout initial &&\n"> <"\tgit checkout master\n">)} ) (C {(test_expect_success)} {(SQ <"apply submodule diff">)} { (SQ <"\n"> <"\t>empty &&\n"> <"\n"> <"\tgit branch second &&\n"> <"\t(\n"> <"\t\tcd init &&\n"> <"\t\techo s >s &&\n"> <"\t\tgit add s &&\n"> <"\t\tgit commit -m \"change subproject\"\n"> <"\t) &&\n"> <"\tgit update-index --add init &&\n"> <"\tgit commit -m \"change init\" &&\n"> <"\tgit format-patch -1 --stdout >P.diff &&\n"> <"\tgit checkout second &&\n"> <"\tgit apply --index P.diff &&\n"> <"\n"> <"\tgit diff --cached master >staged &&\n"> <"\ttest_cmp empty staged\n"> ) } ) (C {(test_expect_success)} {(SQ <"update --init">)} { (SQ <"\n"> <"\tmv init init2 &&\n"> <"\tgit config -f .gitmodules submodule.example.url \"$(pwd)/init2\" &&\n"> <"\tgit config --remove-section submodule.example &&\n"> <"\ttest_must_fail git config submodule.example.url &&\n"> <"\n"> <"\tgit submodule update init 2> update.out &&\n"> <"\tcat update.out &&\n"> <"\ttest_i18ngrep \"not initialized\" update.out &&\n"> <"\ttest_must_fail git rev-parse --resolve-git-dir init/.git &&\n"> <"\n"> <"\tgit submodule update --init init &&\n"> <"\tgit rev-parse --resolve-git-dir init/.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"update --init from subdirectory">)} { (SQ <"\n"> <"\tmv init init2 &&\n"> <"\tgit config -f .gitmodules submodule.example.url \"$(pwd)/init2\" &&\n"> <"\tgit config --remove-section submodule.example &&\n"> <"\ttest_must_fail git config submodule.example.url &&\n"> <"\n"> <"\tmkdir -p sub &&\n"> <"\t(\n"> <"\t\tcd sub &&\n"> <"\t\tgit submodule update ../init 2>update.out &&\n"> <"\t\tcat update.out &&\n"> <"\t\ttest_i18ngrep \"not initialized\" update.out &&\n"> <"\t\ttest_must_fail git rev-parse --resolve-git-dir ../init/.git &&\n"> <"\n"> <"\t\tgit submodule update --init ../init\n"> <"\t) &&\n"> <"\tgit rev-parse --resolve-git-dir init/.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"do not add files from a submodule">)} {(SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\ttest_must_fail git add init/a\n"> <"\n">)} ) (C {(test_expect_success)} {(SQ <"gracefully add/reset submodule with a trailing slash">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit commit -m \"commit subproject\" init &&\n"> <"\t(cd init &&\n"> <"\t echo b > a) &&\n"> <"\tgit add init/ &&\n"> <"\tgit diff --exit-code --cached init &&\n"> <"\tcommit=$(cd init &&\n"> <"\t git commit -m update a >/dev/null &&\n"> <"\t git rev-parse HEAD) &&\n"> <"\tgit add init/ &&\n"> <"\ttest_must_fail git diff --exit-code --cached init &&\n"> <"\ttest $commit = $(git ls-files --stage |\n"> <"\t\tsed -n \"s/^160000 \\([^ ]*\\).*/\\1/p\") &&\n"> <"\tgit reset init/ &&\n"> <"\tgit diff --exit-code --cached init\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-files gracefully handles trailing slash">)} {(SQ <"\n"> <"\n"> <"\ttest \"init\" = \"$(git ls-files init/)\"\n"> <"\n">)} ) (C {(test_expect_success)} {(SQ <"moving to a commit without submodule does not leave empty dir">)} { (SQ <"\n"> <"\trm -rf init &&\n"> <"\tmkdir init &&\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout initial &&\n"> <"\ttest ! -d init &&\n"> <"\tgit checkout second\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule fails">)} {(SQ <"\n"> <"\ttest_must_fail git submodule no-such-subcommand\n">)} ) (C {(test_expect_success)} {(SQ <"add submodules without specifying an explicit path">)} { (SQ <"\n"> <"\tmkdir repo &&\n"> <"\t(\n"> <"\t\tcd repo &&\n"> <"\t\tgit init &&\n"> <"\t\techo r >r &&\n"> <"\t\tgit add r &&\n"> <"\t\tgit commit -m \"repo commit 1\"\n"> <"\t) &&\n"> <"\tgit clone --bare repo/ bare.git &&\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add \"$submodurl/repo\" &&\n"> <"\t\tgit config -f .gitmodules submodule.repo.path repo &&\n"> <"\t\tgit submodule add \"$submodurl/bare.git\" &&\n"> <"\t\tgit config -f .gitmodules submodule.bare.path bare\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"add should fail when path is used by a file">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\ttouch file &&\n"> <"\t\ttest_must_fail\tgit submodule add \"$submodurl/repo\" file\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"add should fail when path is used by an existing directory">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tmkdir empty-dir &&\n"> <"\t\ttest_must_fail git submodule add \"$submodurl/repo\" empty-dir\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"use superproject as upstream when path is relative and no url is set there">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule add ../repo relative &&\n"> <"\t\ttest \"$(git config -f .gitmodules submodule.relative.url)\" = ../repo &&\n"> <"\t\tgit submodule sync relative &&\n"> <"\t\ttest \"$(git config submodule.relative.url)\" = \"$submodurl/repo\"\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"set up for relative path tests">)} { (SQ <"\n"> <"\tmkdir reltest &&\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tgit init &&\n"> <"\t\tmkdir sub &&\n"> <"\t\t(\n"> <"\t\t\tcd sub &&\n"> <"\t\t\tgit init &&\n"> <"\t\t\ttest_commit foo\n"> <"\t\t) &&\n"> <"\t\tgit add sub &&\n"> <"\t\tgit config -f .gitmodules submodule.sub.path sub &&\n"> <"\t\tgit config -f .gitmodules submodule.sub.url ../subrepo &&\n"> <"\t\tcp .git/config pristine-.git-config &&\n"> <"\t\tcp .gitmodules pristine-.gitmodules\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with URL - ssh://hostname/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ssh://hostname/repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = ssh://hostname/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with port-qualified URL - ssh://hostname:22/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ssh://hostname:22/repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = ssh://hostname:22/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo path works with local path - //somewhere else/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url \"//somewhere else/repo\" &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = \"//somewhere else/subrepo\"\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with file URL - file:///tmp/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url file:///tmp/repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = file:///tmp/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with helper URL- helper:://hostname/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url helper:://hostname/repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = helper:://hostname/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with scp-style URL - user@host:repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tgit config remote.origin.url user@host:repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = user@host:subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with scp-style URL - user@host:path/to/repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url user@host:path/to/repo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = user@host:path/to/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - foo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url foo &&\n"> <"\t\t# actual: fails with an error\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - foo/bar">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url foo/bar &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = foo/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - ./foo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ./foo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - ./foo/bar">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ./foo/bar &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = foo/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - ../foo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ../foo &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = ../subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../subrepo works with relative local path - ../foo/bar">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tgit config remote.origin.url ../foo/bar &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.sub.url)\" = ../foo/subrepo\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"../bar/a/b/c works with relative local path - ../foo/bar.git">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd reltest &&\n"> <"\t\tcp pristine-.git-config .git/config &&\n"> <"\t\tcp pristine-.gitmodules .gitmodules &&\n"> <"\t\tmkdir -p a/b/c &&\n"> <"\t\t(cd a/b/c; git init) &&\n"> <"\t\tgit config remote.origin.url ../foo/bar.git &&\n"> <"\t\tgit submodule add ../bar/a/b/c ./a/b/c &&\n"> <"\t\tgit submodule init &&\n"> <"\t\ttest \"$(git config submodule.a/b/c.url)\" = ../foo/bar/a/b/c\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"moving the superproject does not break submodules">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest &&\n"> <"\t\tgit submodule status >expect\n"> <"\t) &&\n"> <"\tmv addtest addtest2 &&\n"> <"\t(\n"> <"\t\tcd addtest2 &&\n"> <"\t\tgit submodule status >actual &&\n"> <"\t\ttest_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add --name allows to replace a submodule with another at the same path">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest2 &&\n"> <"\t\t(\n"> <"\t\t\tcd repo &&\n"> <"\t\t\techo \"$submodurl/repo\" >expect &&\n"> <"\t\t\tgit config remote.origin.url >actual &&\n"> <"\t\t\ttest_cmp expect actual &&\n"> <"\t\t\techo \"gitdir: ../.git/modules/repo\" >expect &&\n"> <"\t\t\ttest_cmp expect .git\n"> <"\t\t) &&\n"> <"\t\trm -rf repo &&\n"> <"\t\tgit rm repo &&\n"> <"\t\tgit submodule add -q --name repo_new \"$submodurl/bare.git\" repo >actual &&\n"> <"\t\ttest_must_be_empty actual &&\n"> <"\t\techo \"gitdir: ../.git/modules/submod\" >expect &&\n"> <"\t\ttest_cmp expect submod/.git &&\n"> <"\t\t(\n"> <"\t\t\tcd repo &&\n"> <"\t\t\techo \"$submodurl/bare.git\" >expect &&\n"> <"\t\t\tgit config remote.origin.url >actual &&\n"> <"\t\t\ttest_cmp expect actual &&\n"> <"\t\t\techo \"gitdir: ../.git/modules/repo_new\" >expect &&\n"> <"\t\t\ttest_cmp expect .git\n"> <"\t\t) &&\n"> <"\t\techo \"repo\" >expect &&\n"> <"\t\ttest_must_fail git config -f .gitmodules submodule.repo.path &&\n"> <"\t\tgit config -f .gitmodules submodule.repo_new.path >actual &&\n"> <"\t\ttest_cmp expect actual&&\n"> <"\t\techo \"$submodurl/repo\" >expect &&\n"> <"\t\ttest_must_fail git config -f .gitmodules submodule.repo.url &&\n"> <"\t\techo \"$submodurl/bare.git\" >expect &&\n"> <"\t\tgit config -f .gitmodules submodule.repo_new.url >actual &&\n"> <"\t\ttest_cmp expect actual &&\n"> <"\t\techo \"$submodurl/repo\" >expect &&\n"> <"\t\tgit config submodule.repo.url >actual &&\n"> <"\t\ttest_cmp expect actual &&\n"> <"\t\techo \"$submodurl/bare.git\" >expect &&\n"> <"\t\tgit config submodule.repo_new.url >actual &&\n"> <"\t\ttest_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"recursive relative submodules stay relative">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -rf super clone2 subsub sub3\" &&\n"> <"\tmkdir subsub &&\n"> <"\t(\n"> <"\t\tcd subsub &&\n"> <"\t\tgit init &&\n"> <"\t\t>t &&\n"> <"\t\tgit add t &&\n"> <"\t\tgit commit -m \"initial commit\"\n"> <"\t) &&\n"> <"\tmkdir sub3 &&\n"> <"\t(\n"> <"\t\tcd sub3 &&\n"> <"\t\tgit init &&\n"> <"\t\t>t &&\n"> <"\t\tgit add t &&\n"> <"\t\tgit commit -m \"initial commit\" &&\n"> <"\t\tgit submodule add ../subsub dirdir/subsub &&\n"> <"\t\tgit commit -m \"add submodule subsub\"\n"> <"\t) &&\n"> <"\tmkdir super &&\n"> <"\t(\n"> <"\t\tcd super &&\n"> <"\t\tgit init &&\n"> <"\t\t>t &&\n"> <"\t\tgit add t &&\n"> <"\t\tgit commit -m \"initial commit\" &&\n"> <"\t\tgit submodule add ../sub3 &&\n"> <"\t\tgit commit -m \"add submodule sub\"\n"> <"\t) &&\n"> <"\tgit clone super clone2 &&\n"> <"\t(\n"> <"\t\tcd clone2 &&\n"> <"\t\tgit submodule update --init --recursive &&\n"> <"\t\techo \"gitdir: ../.git/modules/sub3\" >./sub3/.git_expect &&\n"> < "\t\techo \"gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub\" >./sub3/dirdir/subsub/.git_expect\n" > <"\t) &&\n"> <"\ttest_cmp clone2/sub3/.git_expect clone2/sub3/.git &&\n"> <"\ttest_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add with an existing name fails unless forced">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd addtest2 &&\n"> <"\t\trm -rf repo &&\n"> <"\t\tgit rm repo &&\n"> < "\t\ttest_must_fail git submodule add -q --name repo_new \"$submodurl/repo.git\" repo &&\n" > <"\t\ttest ! -d repo &&\n"> <"\t\ttest_must_fail git config -f .gitmodules submodule.repo_new.path &&\n"> <"\t\ttest_must_fail git config -f .gitmodules submodule.repo_new.url &&\n"> <"\t\techo \"$submodurl/bare.git\" >expect &&\n"> <"\t\tgit config submodule.repo_new.url >actual &&\n"> <"\t\ttest_cmp expect actual &&\n"> <"\t\tgit submodule add -f -q --name repo_new \"$submodurl/repo.git\" repo &&\n"> <"\t\ttest -d repo &&\n"> <"\t\techo \"repo\" >expect &&\n"> <"\t\tgit config -f .gitmodules submodule.repo_new.path >actual &&\n"> <"\t\ttest_cmp expect actual&&\n"> <"\t\techo \"$submodurl/repo.git\" >expect &&\n"> <"\t\tgit config -f .gitmodules submodule.repo_new.url >actual &&\n"> <"\t\ttest_cmp expect actual &&\n"> <"\t\techo \"$submodurl/repo.git\" >expect &&\n"> <"\t\tgit config submodule.repo_new.url >actual &&\n"> <"\t\ttest_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"set up a second submodule">)} { (SQ <"\n"> <"\tgit submodule add ./init2 example2 &&\n"> <"\tgit commit -m \"submodule example2 added\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit works on repository without submodules">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -rf newdirectory\" &&\n"> <"\tmkdir newdirectory &&\n"> <"\t(\n"> <"\t\tcd newdirectory &&\n"> <"\t\tgit init &&\n"> <"\t\t>file &&\n"> <"\t\tgit add file &&\n"> <"\t\tgit commit -m \"repo should not be empty\" &&\n"> <"\t\tgit submodule deinit . &&\n"> <"\t\tgit submodule deinit --all\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit should remove the whole submodule section from .git/config">)} { (SQ <"\n"> <"\tgit config submodule.example.foo bar &&\n"> <"\tgit config submodule.example2.frotz nitfol &&\n"> <"\tgit submodule deinit init &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example2\\.\")\" &&\n"> <"\ttest -f example2/.git &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit from subdirectory">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\tgit config submodule.example.foo bar &&\n"> <"\tmkdir -p sub &&\n"> <"\t(\n"> <"\t\tcd sub &&\n"> <"\t\tgit submodule deinit ../init >../output\n"> <"\t) &&\n"> <"\ttest_i18ngrep \"\\\\.\\\\./init\" output &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example2\\.\")\" &&\n"> <"\ttest -f example2/.git &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit . deinits all initialized submodules">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\tgit config submodule.example.foo bar &&\n"> <"\tgit config submodule.example2.frotz nitfol &&\n"> <"\ttest_must_fail git submodule deinit &&\n"> <"\tgit submodule deinit . >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example2\\.\")\" &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .example2\" actual &&\n"> <"\trmdir init example2\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit --all deinits all initialized submodules">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\tgit config submodule.example.foo bar &&\n"> <"\tgit config submodule.example2.frotz nitfol &&\n"> <"\ttest_must_fail git submodule deinit &&\n"> <"\tgit submodule deinit --all >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example2\\.\")\" &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .example2\" actual &&\n"> <"\trmdir init example2\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit deinits a submodule when its work tree is missing or empty">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\trm -rf init example2/* example2/.git &&\n"> <"\tgit submodule deinit init example2 >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example2\\.\")\" &&\n"> <"\ttest_i18ngrep ! \"Cleared directory .init\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .example2\" actual &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit fails when the submodule contains modifications unless forced">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\techo X >>init/s &&\n"> <"\ttest_must_fail git submodule deinit init &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -f example2/.git &&\n"> <"\tgit submodule deinit -f init >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit fails when the submodule contains untracked files unless forced">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\techo X >>init/untracked &&\n"> <"\ttest_must_fail git submodule deinit init &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -f example2/.git &&\n"> <"\tgit submodule deinit -f init >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit fails when the submodule HEAD does not match unless forced">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\t(\n"> <"\t\tcd init &&\n"> <"\t\tgit checkout HEAD^\n"> <"\t) &&\n"> <"\ttest_must_fail git submodule deinit init &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest -f example2/.git &&\n"> <"\tgit submodule deinit -f init >actual &&\n"> <"\ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\" &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\trmdir init\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit is silent when used on an uninitialized submodule">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\tgit submodule deinit init >actual &&\n"> <"\ttest_i18ngrep \"Submodule .example. (.*) unregistered for path .init\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\tgit submodule deinit init >actual &&\n"> <"\ttest_i18ngrep ! \"Submodule .example. (.*) unregistered for path .init\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\tgit submodule deinit . >actual &&\n"> < "\ttest_i18ngrep ! \"Submodule .example. (.*) unregistered for path .init\" actual &&\n" > <"\ttest_i18ngrep \"Submodule .example2. (.*) unregistered for path .example2\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\tgit submodule deinit . >actual &&\n"> < "\ttest_i18ngrep ! \"Submodule .example. (.*) unregistered for path .init\" actual &&\n" > <"\ttest_i18ngrep ! \"Submodule .example2. (.*) unregistered for path .example2\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\tgit submodule deinit --all >actual &&\n"> < "\ttest_i18ngrep ! \"Submodule .example. (.*) unregistered for path .init\" actual &&\n" > <"\ttest_i18ngrep ! \"Submodule .example2. (.*) unregistered for path .example2\" actual &&\n"> <"\ttest_i18ngrep \"Cleared directory .init\" actual &&\n"> <"\trmdir init example2\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule deinit fails when submodule has a .git directory even when forced">)} { (SQ <"\n"> <"\tgit submodule update --init &&\n"> <"\t(\n"> <"\t\tcd init &&\n"> <"\t\trm .git &&\n"> <"\t\tcp -R ../.git/modules/example .git &&\n"> <"\t\tGIT_WORK_TREE=. git config --unset core.worktree\n"> <"\t) &&\n"> <"\ttest_must_fail git submodule deinit init &&\n"> <"\ttest_must_fail git submodule deinit -f init &&\n"> <"\ttest -d init/.git &&\n"> <"\ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule with UTF-8 name">)} { (SQ <"\n"> <"\tsvname=$(printf \"\\303\\245 \\303\\244\\303\\266\") &&\n"> <"\tmkdir \"$svname\" &&\n"> <"\t(\n"> <"\t\tcd \"$svname\" &&\n"> <"\t\tgit init &&\n"> <"\t\t>sub &&\n"> <"\t\tgit add sub &&\n"> <"\t\tgit commit -m \"init sub\"\n"> <"\t) &&\n"> <"\tgit submodule add ./\"$svname\" &&\n"> <"\tgit submodule >&2 &&\n"> <"\ttest -n \"$(git submodule | grep \"$svname\")\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule add clone shallow submodule">)} { (SQ <"\n"> <"\tmkdir super &&\n"> <"\tpwd=$(pwd) &&\n"> <"\t(\n"> <"\t\tcd super &&\n"> <"\t\tgit init &&\n"> <"\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n"> <"\t\t(\n"> <"\t\t\tcd submodule &&\n"> <"\t\t\ttest 1 = $(git log --oneline | wc -l)\n"> <"\t\t)\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"submodule helper list is not confused by common prefixes">)} { (SQ <"\n"> <"\tmkdir -p dir1/b &&\n"> <"\t(\n"> <"\t\tcd dir1/b &&\n"> <"\t\tgit init &&\n"> <"\t\techo hi >testfile2 &&\n"> <"\t\tgit add . &&\n"> <"\t\tgit commit -m \"test1\"\n"> <"\t) &&\n"> <"\tmkdir -p dir2/b &&\n"> <"\t(\n"> <"\t\tcd dir2/b &&\n"> <"\t\tgit init &&\n"> <"\t\techo hello >testfile1 &&\n"> <"\t\tgit add . &&\n"> <"\t\tgit commit -m \"test2\"\n"> <"\t) &&\n"> <"\tgit submodule add /dir1/b dir1/b &&\n"> <"\tgit submodule add /dir2/b dir2/b &&\n"> <"\tgit commit -m \"first submodule commit\" &&\n"> <"\tgit submodule--helper list dir1/b |cut -c51- >actual &&\n"> <"\techo \"dir1/b\" >expect &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )