2007-06-02 09:27:42 +08: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:
|
2008-01-15 19:13:55 +08:00
|
|
|
# -create a repository in directory init
|
2007-06-02 09:27:42 +08:00
|
|
|
# -add a couple of files
|
2008-01-15 19:13:55 +08:00
|
|
|
# -add directory init to 'superproject', this creates a DIRLINK entry
|
2007-06-02 09:27:42 +08:00
|
|
|
# -add a couple of regular files to enable testing of submodule filtering
|
2008-01-15 19:13:55 +08:00
|
|
|
# -mv init subrepo
|
2007-06-12 03:12:24 +08:00
|
|
|
# -add an entry to .gitmodules for submodule 'example'
|
2007-06-02 09:27:42 +08:00
|
|
|
#
|
|
|
|
test_expect_success 'Prepare submodule testing' '
|
2007-07-18 02:28:28 +08:00
|
|
|
: > t &&
|
|
|
|
git-add t &&
|
|
|
|
git-commit -m "initial commit" &&
|
|
|
|
git branch initial HEAD &&
|
2008-01-15 19:13:55 +08:00
|
|
|
mkdir init &&
|
|
|
|
cd init &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git init &&
|
2007-06-02 09:27:42 +08:00
|
|
|
echo a >a &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git add a &&
|
2007-06-02 09:27:42 +08:00
|
|
|
git-commit -m "submodule commit 1" &&
|
|
|
|
git-tag -a -m "rev-1" rev-1 &&
|
2007-07-03 13:52:14 +08:00
|
|
|
rev1=$(git rev-parse HEAD) &&
|
2007-06-02 09:27:42 +08:00
|
|
|
if test -z "$rev1"
|
|
|
|
then
|
2007-07-03 13:52:14 +08:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
|
|
|
fi &&
|
|
|
|
cd .. &&
|
|
|
|
echo a >a &&
|
|
|
|
echo z >z &&
|
2008-01-15 19:13:55 +08:00
|
|
|
git add a init z &&
|
2007-06-02 09:27:42 +08:00
|
|
|
git-commit -m "super commit 1" &&
|
2008-01-15 19:13:55 +08:00
|
|
|
mv init .subrepo &&
|
|
|
|
GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
|
2007-06-12 03:12:24 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should fail for unmapped paths' '
|
|
|
|
if git-submodule status
|
|
|
|
then
|
|
|
|
echo "[OOPS] submodule status succeeded"
|
|
|
|
false
|
2008-01-15 19:13:55 +08:00
|
|
|
elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
|
2007-06-12 03:12:24 +08:00
|
|
|
then
|
2007-07-03 13:52:14 +08:00
|
|
|
echo "[OOPS] git config failed to update .gitmodules"
|
2007-06-12 03:12:24 +08:00
|
|
|
false
|
|
|
|
fi
|
2007-06-02 09:27:42 +08: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 17:13:02 +08:00
|
|
|
test_expect_success 'init should register submodule url in .git/config' '
|
|
|
|
git-submodule init &&
|
2007-07-03 13:52:14 +08:00
|
|
|
url=$(git config submodule.example.url) &&
|
2008-01-15 19:13:55 +08:00
|
|
|
if test "$url" != "git://example.com/init.git"
|
2007-06-06 17:13:02 +08:00
|
|
|
then
|
|
|
|
echo "[OOPS] init succeeded but submodule url is wrong"
|
|
|
|
false
|
2008-07-12 23:47:52 +08:00
|
|
|
elif test_must_fail git config submodule.example.url ./.subrepo
|
2007-06-06 17:13:02 +08: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 19:13:55 +08:00
|
|
|
echo "hello" >init &&
|
2007-06-06 17:13:02 +08:00
|
|
|
if git-submodule update
|
2007-06-02 09:27:42 +08:00
|
|
|
then
|
2007-06-06 17:13:02 +08:00
|
|
|
echo "[OOPS] update should have failed"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
2008-01-15 19:13:55 +08:00
|
|
|
elif test "$(cat init)" != "hello"
|
2007-06-02 09:27:42 +08:00
|
|
|
then
|
2008-01-15 19:13:55 +08:00
|
|
|
echo "[OOPS] update failed but init file was molested"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
|
|
|
else
|
2008-01-15 19:13:55 +08:00
|
|
|
rm init
|
2007-06-02 09:27:42 +08:00
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 17:13:02 +08:00
|
|
|
test_expect_success 'update should fail when path is used by a nonempty directory' '
|
2008-01-15 19:13:55 +08:00
|
|
|
mkdir init &&
|
|
|
|
echo "hello" >init/a &&
|
2007-06-06 17:13:02 +08:00
|
|
|
if git-submodule update
|
2007-06-02 09:27:42 +08:00
|
|
|
then
|
2007-06-06 17:13:02 +08:00
|
|
|
echo "[OOPS] update should have failed"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
2008-01-15 19:13:55 +08:00
|
|
|
elif test "$(cat init/a)" != "hello"
|
2007-06-02 09:27:42 +08:00
|
|
|
then
|
2008-01-15 19:13:55 +08:00
|
|
|
echo "[OOPS] update failed but init/a was molested"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
|
|
|
else
|
2008-01-15 19:13:55 +08:00
|
|
|
rm init/a
|
2007-06-02 09:27:42 +08:00
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2007-06-06 17:13:02 +08:00
|
|
|
test_expect_success 'update should work when path is an empty dir' '
|
2008-01-15 19:13:55 +08:00
|
|
|
rm -rf init &&
|
|
|
|
mkdir init &&
|
2007-06-06 17:13:02 +08:00
|
|
|
git-submodule update &&
|
2008-01-15 19:13:55 +08:00
|
|
|
head=$(cd init && git rev-parse HEAD) &&
|
2007-06-02 09:27:42 +08: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 17:13:02 +08:00
|
|
|
test_expect_success 'status should be "up-to-date" after update' '
|
2007-06-02 09:27:42 +08:00
|
|
|
git-submodule status | grep "^ $rev1"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'status should be "modified" after submodule commit' '
|
2008-01-15 19:13:55 +08:00
|
|
|
cd init &&
|
2007-06-02 09:27:42 +08:00
|
|
|
echo b >b &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git add b &&
|
2007-06-02 09:27:42 +08:00
|
|
|
git-commit -m "submodule commit 2" &&
|
2007-07-03 13:52:14 +08:00
|
|
|
rev2=$(git rev-parse HEAD) &&
|
2007-06-02 09:27:42 +08:00
|
|
|
cd .. &&
|
|
|
|
if test -z "$rev2"
|
|
|
|
then
|
2007-07-03 13:52:14 +08:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 09:27:42 +08:00
|
|
|
false
|
|
|
|
fi &&
|
|
|
|
git-submodule status | grep "^+$rev2"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'the --cached sha1 should be rev1' '
|
|
|
|
git-submodule --cached status | grep "^+$rev1"
|
|
|
|
'
|
|
|
|
|
2007-09-08 18:30:22 +08:00
|
|
|
test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
|
|
|
|
git-diff | grep "^+Subproject commit $rev2"
|
|
|
|
'
|
|
|
|
|
2007-06-02 09:27:42 +08:00
|
|
|
test_expect_success 'update should checkout rev1' '
|
2008-01-15 19:13:55 +08:00
|
|
|
git-submodule update init &&
|
|
|
|
head=$(cd init && git rev-parse HEAD) &&
|
2007-06-02 09:27:42 +08:00
|
|
|
if test -z "$head"
|
|
|
|
then
|
2007-07-03 13:52:14 +08:00
|
|
|
echo "[OOPS] submodule git rev-parse returned nothing"
|
2007-06-02 09:27:42 +08: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"
|
|
|
|
'
|
|
|
|
|
2007-07-18 02:28:28 +08:00
|
|
|
test_expect_success 'checkout superproject with subproject already present' '
|
|
|
|
git-checkout initial &&
|
|
|
|
git-checkout master
|
|
|
|
'
|
|
|
|
|
2007-08-16 01:22:09 +08:00
|
|
|
test_expect_success 'apply submodule diff' '
|
|
|
|
git branch second &&
|
|
|
|
(
|
2008-01-15 19:13:55 +08:00
|
|
|
cd init &&
|
2007-08-16 01:22:09 +08:00
|
|
|
echo s >s &&
|
|
|
|
git add s &&
|
|
|
|
git commit -m "change subproject"
|
|
|
|
) &&
|
2008-01-15 19:13:55 +08:00
|
|
|
git update-index --add init &&
|
|
|
|
git-commit -m "change init" &&
|
2007-08-16 01:22:09 +08:00
|
|
|
git-format-patch -1 --stdout >P.diff &&
|
|
|
|
git checkout second &&
|
|
|
|
git apply --index P.diff &&
|
|
|
|
D=$(git diff --cached master) &&
|
|
|
|
test -z "$D"
|
|
|
|
'
|
|
|
|
|
2008-05-16 18:23:03 +08: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
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-06-02 09:27:42 +08:00
|
|
|
test_done
|