1293 lines
35 KiB
Bash
Executable File
1293 lines
35 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2007 Lars Hjemli
|
|
#
|
|
|
|
test_description='Basic porcelain support for submodules
|
|
|
|
This test tries to verify basic sanity of the init, update and status
|
|
subcommands of git submodule.
|
|
'
|
|
|
|
. ./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 'submodule update aborts on missing gitmodules url' '
|
|
test_when_finished "git update-index --remove sub" &&
|
|
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
|
|
test_when_finished "rm -f .gitmodules" &&
|
|
git config -f .gitmodules submodule.s.path sub &&
|
|
test_must_fail git submodule init
|
|
'
|
|
|
|
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.
|
|
submodurl=$(pwd -P)
|
|
|
|
listbranches() {
|
|
git for-each-ref --format='%(refname)' 'refs/heads/*'
|
|
}
|
|
|
|
inspect() {
|
|
dir=$1 &&
|
|
dotdot="${2:-..}" &&
|
|
|
|
(
|
|
cd "$dir" &&
|
|
listbranches >"$dotdot/heads" &&
|
|
{ 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 to reconfigure existing submodule with --force' '
|
|
(
|
|
cd addtest-ignore &&
|
|
git submodule add --force bogus-url submod &&
|
|
git submodule add -b initial "$submodurl" submod-branch &&
|
|
test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
|
|
test "bogus-url" = "$(git config submodule.submod.url)" &&
|
|
# Restore the url
|
|
git submodule add --force "$submodurl" submod
|
|
test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
|
|
test "$submodurl" = "$(git config submodule.submod.url)"
|
|
)
|
|
'
|
|
|
|
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//.. &&
|
|