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