2007-06-02 05:27:42 +04:00
|
|
|
#!/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
|
2008-09-03 12:59:33 +04:00
|
|
|
subcommands of git submodule.
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test setup:
|
2008-01-15 14:13:55 +03:00
|
|
|
# -create a repository in directory init
|
2007-06-02 05:27:42 +04:00
|
|
|
# -add a couple of files
|
2008-01-15 14:13:55 +03:00
|
|
|
# -add directory init to 'superproject', this creates a DIRLINK entry
|
2007-06-02 05:27:42 +04:00
|
|
|
# -add a couple of regular files to enable testing of submodule filtering
|
2008-01-15 14:13:55 +03:00
|
|
|
# -mv init subrepo
|
2007-06-11 23:12:24 +04:00
|
|
|
# -add an entry to .gitmodules for submodule 'example'
|
2007-06-02 05:27:42 +04:00
|
|
|
#
|
|
|
|
test_expect_success 'Prepare submodule testing' '
|
2007-07-17 22:28:28 +04:00
|
|
|
: > t &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git add t &&
|
|
|
|
git commit -m "initial commit" &&
|
2007-07-17 22:28:28 +04:00
|
|
|
git branch initial HEAD &&
|
2008-01-15 14:13:55 +03:00
|
|
|
mkdir init &&
|
|
|
|
cd init &&
|
2007-07-03 09:52:14 +04:00
|
|
|
git init &&
|
2007-06-02 05:27:42 +04:00
|
|
|
echo a >a &&
|
2007-07-03 09:52:14 +04:00
|
|
|
git add a &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git commit -m "submodule commit 1" &&
|
|
|
|
git tag -a -m "rev-1" rev-1 &&
|
2007-07-03 09:52:14 +04:00
|
|
|
rev1=$(git rev-parse HEAD) &&
|
2007-06-02 05:27:42 +04:00
|
|
|
if test -z "$rev1"
|
|
|
|
then
|
2007-07-03 09:52:14 +04:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
|
|
|
fi &&
|
|
|
|
cd .. &&
|
|
|
|
echo a >a &&
|
|
|
|
echo z >z &&
|
2008-01-15 14:13:55 +03:00
|
|
|
git add a init z &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git commit -m "super commit 1" &&
|
2008-01-15 14:13:55 +03:00
|
|
|
mv init .subrepo &&
|
|
|
|
GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
|
2007-06-11 23:12:24 +04:00
|
|
|
'
|
|
|
|
|
2009-03-03 18:08:20 +03:00
|
|
|
test_expect_success 'Prepare submodule add testing' '
|
|
|
|
submodurl=$(pwd)
|
|
|
|
(
|
|
|
|
mkdir addtest &&
|
|
|
|
cd addtest &&
|
|
|
|
git init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule add' '
|
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add "$submodurl" submod &&
|
|
|
|
git submodule init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-04-19 07:42:07 +04:00
|
|
|
test_expect_success 'submodule add --branch' '
|
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add -b initial "$submodurl" submod-branch &&
|
|
|
|
git submodule init &&
|
|
|
|
cd submod-branch &&
|
|
|
|
git branch | grep initial
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-03-03 18:08:21 +03:00
|
|
|
test_expect_success 'submodule add with ./ in path' '
|
2009-03-03 18:08:20 +03:00
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
|
|
|
|
git submodule init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-03-03 18:08:21 +03:00
|
|
|
test_expect_success 'submodule add with // in path' '
|
2009-03-03 18:08:20 +03:00
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add "$submodurl" slashslashsubmod///frotz// &&
|
|
|
|
git submodule init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-03-03 18:08:21 +03:00
|
|
|
test_expect_success 'submodule add with /.. in path' '
|
2009-03-03 18:08:20 +03:00
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
|
|
|
|
git submodule init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-03-03 18:08:21 +03:00
|
|
|
test_expect_success 'submodule add with ./, /.. and // in path' '
|
2009-03-03 18:08:20 +03:00
|
|
|
(
|
|
|
|
cd addtest &&
|
|
|
|
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
|
|
|
|
git submodule init
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2007-06-11 23:12:24 +04:00
|
|
|
test_expect_success 'status should fail for unmapped paths' '
|
2008-09-03 12:59:33 +04:00
|
|
|
if git submodule status
|
2007-06-11 23:12:24 +04:00
|
|
|
then
|
|
|
|
echo "[OOPS] submodule status succeeded"
|
|
|
|
false
|
2008-01-15 14:13:55 +03:00
|
|
|
elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
|
2007-06-11 23:12:24 +04:00
|
|
|
then
|
2007-07-03 09:52:14 +04:00
|
|
|
echo "[OOPS] git config failed to update .gitmodules"
|
2007-06-11 23:12:24 +04:00
|
|
|
false
|
|
|
|
fi
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should only print one line' '
|
2008-09-03 12:59:33 +04:00
|
|
|
lines=$(git submodule status | wc -l) &&
|
2007-06-02 05:27:42 +04:00
|
|
|
test $lines = 1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should initially be "missing"' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule status | grep "^-$rev1"
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
2007-06-06 13:13:02 +04:00
|
|
|
test_expect_success 'init should register submodule url in .git/config' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule init &&
|
2007-07-03 09:52:14 +04:00
|
|
|
url=$(git config submodule.example.url) &&
|
2008-01-15 14:13:55 +03:00
|
|
|
if test "$url" != "git://example.com/init.git"
|
2007-06-06 13:13:02 +04:00
|
|
|
then
|
|
|
|
echo "[OOPS] init succeeded but submodule url is wrong"
|
|
|
|
false
|
2008-07-12 19:47:52 +04:00
|
|
|
elif test_must_fail git config submodule.example.url ./.subrepo
|
2007-06-06 13:13:02 +04:00
|
|
|
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' '
|
2008-01-15 14:13:55 +03:00
|
|
|
echo "hello" >init &&
|
2008-09-03 12:59:33 +04:00
|
|
|
if git submodule update
|
2007-06-02 05:27:42 +04:00
|
|
|
then
|
2007-06-06 13:13:02 +04:00
|
|
|
echo "[OOPS] update should have failed"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
2008-01-15 14:13:55 +03:00
|
|
|
elif test "$(cat init)" != "hello"
|
2007-06-02 05:27:42 +04:00
|
|
|
then
|
2008-01-15 14:13:55 +03:00
|
|
|
echo "[OOPS] update failed but init file was molested"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
|
|
|
else
|
2008-01-15 14:13:55 +03:00
|
|
|
rm init
|
2007-06-02 05:27:42 +04:00
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 13:13:02 +04:00
|
|
|
test_expect_success 'update should fail when path is used by a nonempty directory' '
|
2008-01-15 14:13:55 +03:00
|
|
|
mkdir init &&
|
|
|
|
echo "hello" >init/a &&
|
2008-09-03 12:59:33 +04:00
|
|
|
if git submodule update
|
2007-06-02 05:27:42 +04:00
|
|
|
then
|
2007-06-06 13:13:02 +04:00
|
|
|
echo "[OOPS] update should have failed"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
2008-01-15 14:13:55 +03:00
|
|
|
elif test "$(cat init/a)" != "hello"
|
2007-06-02 05:27:42 +04:00
|
|
|
then
|
2008-01-15 14:13:55 +03:00
|
|
|
echo "[OOPS] update failed but init/a was molested"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
|
|
|
else
|
2008-01-15 14:13:55 +03:00
|
|
|
rm init/a
|
2007-06-02 05:27:42 +04:00
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 13:13:02 +04:00
|
|
|
test_expect_success 'update should work when path is an empty dir' '
|
2008-01-15 14:13:55 +03:00
|
|
|
rm -rf init &&
|
|
|
|
mkdir init &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule update &&
|
2008-01-15 14:13:55 +03:00
|
|
|
head=$(cd init && git rev-parse HEAD) &&
|
2007-06-02 05:27:42 +04:00
|
|
|
if test -z "$head"
|
|
|
|
then
|
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2007-06-06 13:13:02 +04:00
|
|
|
test_expect_success 'status should be "up-to-date" after update' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule status | grep "^ $rev1"
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should be "modified" after submodule commit' '
|
2008-01-15 14:13:55 +03:00
|
|
|
cd init &&
|
2007-06-02 05:27:42 +04:00
|
|
|
echo b >b &&
|
2007-07-03 09:52:14 +04:00
|
|
|
git add b &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git commit -m "submodule commit 2" &&
|
2007-07-03 09:52:14 +04:00
|
|
|
rev2=$(git rev-parse HEAD) &&
|
2007-06-02 05:27:42 +04:00
|
|
|
cd .. &&
|
|
|
|
if test -z "$rev2"
|
|
|
|
then
|
2007-07-03 09:52:14 +04:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 05:27:42 +04:00
|
|
|
false
|
|
|
|
fi &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule status | grep "^+$rev2"
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'the --cached sha1 should be rev1' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule --cached status | grep "^+$rev1"
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
2007-09-08 14:30:22 +04:00
|
|
|
test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git diff | grep "^+Subproject commit $rev2"
|
2007-09-08 14:30:22 +04:00
|
|
|
'
|
|
|
|
|
2007-06-02 05:27:42 +04:00
|
|
|
test_expect_success 'update should checkout rev1' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule update init &&
|
2008-01-15 14:13:55 +03:00
|
|
|
head=$(cd init && git rev-parse HEAD) &&
|
2007-06-02 05:27:42 +04:00
|
|
|
if test -z "$head"
|
|
|
|
then
|
2007-07-03 09:52:14 +04:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 05:27:42 +04:00
|
|
|
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' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git submodule status | grep "^ $rev1"
|
2007-06-02 05:27:42 +04:00
|
|
|
'
|
|
|
|
|
2007-07-17 22:28:28 +04:00
|
|
|
test_expect_success 'checkout superproject with subproject already present' '
|
2008-09-03 12:59:33 +04:00
|
|
|
git checkout initial &&
|
|
|
|
git checkout master
|
2007-07-17 22:28:28 +04:00
|
|
|
'
|
|
|
|
|
2007-08-15 21:22:09 +04:00
|
|
|
test_expect_success 'apply submodule diff' '
|
|
|
|
git branch second &&
|
|
|
|
(
|
2008-01-15 14:13:55 +03:00
|
|
|
cd init &&
|
2007-08-15 21:22:09 +04:00
|
|
|
echo s >s &&
|
|
|
|
git add s &&
|
|
|
|
git commit -m "change subproject"
|
|
|
|
) &&
|
2008-01-15 14:13:55 +03:00
|
|
|
git update-index --add init &&
|
2008-09-03 12:59:33 +04:00
|
|
|
git commit -m "change init" &&
|
|
|
|
git format-patch -1 --stdout >P.diff &&
|
2007-08-15 21:22:09 +04:00
|
|
|
git checkout second &&
|
|
|
|
git apply --index P.diff &&
|
|
|
|
D=$(git diff --cached master) &&
|
|
|
|
test -z "$D"
|
|
|
|
'
|
|
|
|
|
2008-05-16 14:23:03 +04:00
|
|
|
test_expect_success 'update --init' '
|
|
|
|
|
|
|
|
mv init init2 &&
|
|
|
|
git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
|
|
|
|
git config --remove-section submodule.example
|
|
|
|
git submodule update init > update.out &&
|
|
|
|
grep "not initialized" update.out &&
|
|
|
|
test ! -d init/.git &&
|
|
|
|
git submodule update --init init &&
|
|
|
|
test -d init/.git
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-01-02 21:08:40 +03:00
|
|
|
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 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")
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-02-07 16:43:03 +03:00
|
|
|
test_expect_success 'ls-files gracefully handles trailing slash' '
|
|
|
|
|
|
|
|
test "init" = "$(git ls-files init/)"
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2010-01-11 05:59:54 +03:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2009-02-07 16:43:15 +03:00
|
|
|
test_expect_success 'submodule <invalid-path> warns' '
|
|
|
|
|
|
|
|
git submodule no-such-submodule 2> output.err &&
|
|
|
|
grep "^error: .*no-such-submodule" output.err
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-09-22 19:10:12 +04:00
|
|
|
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" &&
|
|
|
|
cd .. &&
|
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2007-06-02 05:27:42 +04:00
|
|
|
test_done
|