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
|
|
|
|
subcommands of git-submodule.
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test setup:
|
|
|
|
# -create a repository in directory lib
|
|
|
|
# -add a couple of files
|
|
|
|
# -add directory lib to 'superproject', this creates a DIRLINK entry
|
|
|
|
# -add a couple of regular files to enable testing of submodule filtering
|
|
|
|
# -mv lib 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' '
|
|
|
|
mkdir lib &&
|
|
|
|
cd lib &&
|
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 &&
|
2007-06-02 03:27:42 +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 &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git add a lib z &&
|
2007-06-02 03:27:42 +02:00
|
|
|
git-commit -m "super commit 1" &&
|
|
|
|
mv lib .subrepo &&
|
2007-07-03 07:52:14 +02:00
|
|
|
GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git
|
2007-06-11 21:12:24 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should fail for unmapped paths' '
|
|
|
|
if git-submodule status
|
|
|
|
then
|
|
|
|
echo "[OOPS] submodule status succeeded"
|
|
|
|
false
|
2007-07-03 07:52:14 +02:00
|
|
|
elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib
|
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' '
|
|
|
|
lines=$(git-submodule status | wc -l) &&
|
|
|
|
test $lines = 1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should initially be "missing"' '
|
|
|
|
git-submodule status | grep "^-$rev1"
|
|
|
|
'
|
|
|
|
|
2007-06-06 11:13:02 +02:00
|
|
|
test_expect_success 'init should register submodule url in .git/config' '
|
|
|
|
git-submodule init &&
|
2007-07-03 07:52:14 +02:00
|
|
|
url=$(git config submodule.example.url) &&
|
2007-06-06 11:13:02 +02:00
|
|
|
if test "$url" != "git://example.com/lib.git"
|
|
|
|
then
|
|
|
|
echo "[OOPS] init succeeded but submodule url is wrong"
|
|
|
|
false
|
2007-07-03 07:52:14 +02:00
|
|
|
elif ! 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' '
|
2007-06-02 03:27:42 +02:00
|
|
|
echo "hello" >lib &&
|
2007-06-06 11:13:02 +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
|
2007-06-11 21:12:21 +02:00
|
|
|
elif test "$(cat lib)" != "hello"
|
2007-06-02 03:27:42 +02:00
|
|
|
then
|
2007-06-06 11:13:02 +02:00
|
|
|
echo "[OOPS] update failed but lib file was molested"
|
2007-06-02 03:27:42 +02:00
|
|
|
false
|
|
|
|
else
|
|
|
|
rm lib
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 11:13:02 +02:00
|
|
|
test_expect_success 'update should fail when path is used by a nonempty directory' '
|
2007-06-02 03:27:42 +02:00
|
|
|
mkdir lib &&
|
|
|
|
echo "hello" >lib/a &&
|
2007-06-06 11:13:02 +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
|
|
|
|
elif test "$(cat lib/a)" != "hello"
|
|
|
|
then
|
2007-06-06 11:13:02 +02:00
|
|
|
echo "[OOPS] update failed but lib/a was molested"
|
2007-06-02 03:27:42 +02:00
|
|
|
false
|
|
|
|
else
|
|
|
|
rm lib/a
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 11:13:02 +02:00
|
|
|
test_expect_success 'update should work when path is an empty dir' '
|
2007-06-02 03:27:42 +02:00
|
|
|
rm -rf lib &&
|
|
|
|
mkdir lib &&
|
2007-06-06 11:13:02 +02:00
|
|
|
git-submodule update &&
|
2007-07-03 07:52:14 +02:00
|
|
|
head=$(cd lib && 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' '
|
2007-06-02 03:27:42 +02:00
|
|
|
git-submodule status | grep "^ $rev1"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should be "modified" after submodule commit' '
|
|
|
|
cd lib &&
|
|
|
|
echo b >b &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git add b &&
|
2007-06-02 03:27:42 +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 &&
|
|
|
|
git-submodule status | grep "^+$rev2"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'the --cached sha1 should be rev1' '
|
|
|
|
git-submodule --cached status | grep "^+$rev1"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update should checkout rev1' '
|
|
|
|
git-submodule update &&
|
2007-07-03 07:52:14 +02:00
|
|
|
head=$(cd lib && 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' '
|
|
|
|
git-submodule status | grep "^ $rev1"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|