Merge branch 'jn/submodule-basic-test'

* jn/submodule-basic-test:
  t7400: clarify submodule update tests
  t7400: clarify 'submodule add' tests
  t7400: split setup into multiple tests
This commit is contained in:
Junio C Hamano 2010-05-21 04:02:19 -07:00
commit 465ef577b5

View File

@ -11,226 +11,292 @@ subcommands of git submodule.
. ./test-lib.sh . ./test-lib.sh
# test_expect_success 'setup - initial commit' '
# Test setup: >t &&
# -create a repository in directory init
# -add a couple of files
# -add directory init to 'superproject', this creates a DIRLINK entry
# -add a couple of regular files to enable testing of submodule filtering
# -mv init subrepo
# -add an entry to .gitmodules for submodule 'example'
#
test_expect_success 'Prepare submodule testing' '
: > t &&
git add t && git add t &&
git commit -m "initial commit" && git commit -m "initial commit" &&
git branch initial HEAD && git branch initial
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 &&
rev1=$(git rev-parse HEAD) &&
if test -z "$rev1"
then
echo "[OOPS] submodule git rev-parse returned nothing"
false
fi &&
cd .. &&
echo a >a &&
echo z >z &&
git add a init z &&
git commit -m "super commit 1" &&
mv init .subrepo &&
GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
' '
test_expect_success 'Prepare submodule add testing' ' test_expect_success 'setup - repository in init subdirectory' '
submodurl=$(pwd) mkdir init &&
( (
mkdir addtest && cd init &&
cd addtest && git 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
'
# The 'submodule add' tests need some repository to add as a submodule.
# The trash directory is a good one as any.
submodurl=$TRASH_DIRECTORY
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' ' test_expect_success 'submodule add' '
echo "refs/heads/master" >expect &&
>empty &&
( (
cd addtest && cd addtest &&
git submodule add "$submodurl" submod && git submodule add "$submodurl" submod &&
git submodule init 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 --branch' ' 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 && cd addtest &&
git submodule add -b initial "$submodurl" submod-branch && git submodule add -b initial "$submodurl" submod-branch &&
git submodule init && git submodule init
cd submod-branch && ) &&
git branch | grep initial
) 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' ' test_expect_success 'submodule add with ./ in path' '
echo "refs/heads/master" >expect &&
>empty &&
( (
cd addtest && cd addtest &&
git submodule add "$submodurl" ././dotsubmod/./frotz/./ && git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
git submodule init 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' ' test_expect_success 'submodule add with // in path' '
echo "refs/heads/master" >expect &&
>empty &&
( (
cd addtest && cd addtest &&
git submodule add "$submodurl" slashslashsubmod///frotz// && git submodule add "$submodurl" slashslashsubmod///frotz// &&
git submodule init 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' ' test_expect_success 'submodule add with /.. in path' '
echo "refs/heads/master" >expect &&
>empty &&
( (
cd addtest && cd addtest &&
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
git submodule init 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' ' test_expect_success 'submodule add with ./, /.. and // in path' '
echo "refs/heads/master" >expect &&
>empty &&
( (
cd addtest && cd addtest &&
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
git submodule init 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 'setup - add an example entry to .gitmodules' '
GIT_CONFIG=.gitmodules \
git config submodule.example.url git://example.com/init.git
' '
test_expect_success 'status should fail for unmapped paths' ' test_expect_success 'status should fail for unmapped paths' '
if git submodule status test_must_fail git submodule status
then '
echo "[OOPS] submodule status succeeded"
false test_expect_success 'setup - map path in .gitmodules' '
elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init cat <<\EOF >expect &&
then [submodule "example"]
echo "[OOPS] git config failed to update .gitmodules" url = git://example.com/init.git
false path = init
fi EOF
GIT_CONFIG=.gitmodules git config submodule.example.path init &&
test_cmp expect .gitmodules
' '
test_expect_success 'status should only print one line' ' test_expect_success 'status should only print one line' '
lines=$(git submodule status | wc -l) && git submodule status >lines &&
test $lines = 1 test $(wc -l <lines) = 1
'
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"' ' test_expect_success 'status should initially be "missing"' '
git submodule status | grep "^-$rev1" git submodule status >lines &&
grep "^-$rev1" lines
' '
test_expect_success 'init should register submodule url in .git/config' ' test_expect_success 'init should register submodule url in .git/config' '
echo git://example.com/init.git >expect &&
git submodule init && git submodule init &&
url=$(git config submodule.example.url) && git config submodule.example.url >url &&
if test "$url" != "git://example.com/init.git" git config submodule.example.url ./.subrepo &&
then
echo "[OOPS] init succeeded but submodule url is wrong" test_cmp expect url
false
elif test_must_fail git config submodule.example.url ./.subrepo
then
echo "[OOPS] init succeeded but update of url failed"
false
fi
' '
test_expect_success 'update should fail when path is used by a file' ' test_expect_success 'update should fail when path is used by a file' '
echo hello >expect &&
echo "hello" >init && echo "hello" >init &&
if git submodule update test_must_fail git submodule update &&
then
echo "[OOPS] update should have failed" test_cmp expect init
false
elif test "$(cat init)" != "hello"
then
echo "[OOPS] update failed but init file was molested"
false
else
rm init
fi
' '
test_expect_success 'update should fail when path is used by a nonempty directory' ' test_expect_success 'update should fail when path is used by a nonempty directory' '
echo hello >expect &&
rm -fr init &&
mkdir init && mkdir init &&
echo "hello" >init/a && echo "hello" >init/a &&
if git submodule update
then test_must_fail git submodule update &&
echo "[OOPS] update should have failed"
false test_cmp expect init/a
elif test "$(cat init/a)" != "hello"
then
echo "[OOPS] update failed but init/a was molested"
false
else
rm init/a
fi
' '
test_expect_success 'update should work when path is an empty dir' ' test_expect_success 'update should work when path is an empty dir' '
rm -rf init && rm -fr init &&
rm -f head-sha1 &&
echo "$rev1" >expect &&
mkdir init && mkdir init &&
git submodule update && git submodule update &&
head=$(cd init && git rev-parse HEAD) &&
if test -z "$head" inspect init &&
then test_cmp expect head-sha1
echo "[OOPS] Failed to obtain submodule head"
false
elif test "$head" != "$rev1"
then
echo "[OOPS] Submodule head is $head but should have been $rev1"
false
fi
' '
test_expect_success 'status should be "up-to-date" after update' ' test_expect_success 'status should be "up-to-date" after update' '
git submodule status | grep "^ $rev1" git submodule status >list &&
grep "^ $rev1" list
' '
test_expect_success 'status should be "modified" after submodule commit' ' test_expect_success 'status should be "modified" after submodule commit' '
cd init && (
echo b >b && cd init &&
git add b && echo b >b &&
git commit -m "submodule commit 2" && git add b &&
rev2=$(git rev-parse HEAD) && git commit -m "submodule commit 2"
cd .. && ) &&
if test -z "$rev2"
then rev2=$(cd init && git rev-parse HEAD) &&
echo "[OOPS] submodule git rev-parse returned nothing" test -n "$rev2" &&
false git submodule status >list &&
fi &&
git submodule status | grep "^+$rev2" grep "^+$rev2" list
' '
test_expect_success 'the --cached sha1 should be rev1' ' test_expect_success 'the --cached sha1 should be rev1' '
git submodule --cached status | grep "^+$rev1" git submodule --cached status >list &&
grep "^+$rev1" list
' '
test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
git diff | grep "^+Subproject commit $rev2" git diff >diff &&
grep "^+Subproject commit $rev2" diff
' '
test_expect_success 'update should checkout rev1' ' test_expect_success 'update should checkout rev1' '
rm -f head-sha1 &&
echo "$rev1" >expect &&
git submodule update init && git submodule update init &&
head=$(cd init && git rev-parse HEAD) && inspect init &&
if test -z "$head"
then test_cmp expect head-sha1
echo "[OOPS] submodule git rev-parse returned nothing"
false
elif test "$head" != "$rev1"
then
echo "[OOPS] init did not checkout correct head"
false
fi
' '
test_expect_success 'status should be "up-to-date" after update' ' test_expect_success 'status should be "up-to-date" after update' '
git submodule status | grep "^ $rev1" git submodule status >list &&
grep "^ $rev1" list
' '
test_expect_success 'checkout superproject with subproject already present' ' test_expect_success 'checkout superproject with subproject already present' '
@ -239,6 +305,8 @@ test_expect_success 'checkout superproject with subproject already present' '
' '
test_expect_success 'apply submodule diff' ' test_expect_success 'apply submodule diff' '
>empty &&
git branch second && git branch second &&
( (
cd init && cd init &&
@ -251,21 +319,24 @@ test_expect_success 'apply submodule diff' '
git format-patch -1 --stdout >P.diff && git format-patch -1 --stdout >P.diff &&
git checkout second && git checkout second &&
git apply --index P.diff && git apply --index P.diff &&
D=$(git diff --cached master) &&
test -z "$D" git diff --cached master >staged &&
test_cmp empty staged
' '
test_expect_success 'update --init' ' test_expect_success 'update --init' '
mv init init2 && mv init init2 &&
git config -f .gitmodules submodule.example.url "$(pwd)/init2" && git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
git config --remove-section submodule.example git config --remove-section submodule.example &&
test_must_fail git config submodule.example.url &&
git submodule update init > update.out && git submodule update init > update.out &&
cat update.out &&
grep "not initialized" update.out && grep "not initialized" update.out &&
test ! -d init/.git && ! test -d init/.git &&
git submodule update --init init && git submodule update --init init &&
test -d init/.git test -d init/.git
' '
test_expect_success 'do not add files from a submodule' ' test_expect_success 'do not add files from a submodule' '