-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test-script for git-submodule
This test tries to verify basic sanity of git-submodule, i.e. that it is able to clone and update a submodule repository, that its status output is sane, and that it barfs when the submodule path is occupied during init. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
- Loading branch information
Lars Hjemli
authored and
Junio C Hamano
committed
Jun 2, 2007
1 parent
70c7ac2
commit 88961ef
Showing
1 changed file
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/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 | ||
# -add an entry to .gitmodules for path 'lib' | ||
# | ||
test_expect_success 'Prepare submodule testing' ' | ||
mkdir lib && | ||
cd lib && | ||
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 lib z && | ||
git-commit -m "super commit 1" && | ||
mv lib .subrepo && | ||
GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo | ||
' | ||
|
||
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" | ||
' | ||
|
||
test_expect_success 'init should fail when path is used by a file' ' | ||
echo "hello" >lib && | ||
if git-submodule init | ||
then | ||
echo "[OOPS] init should have failed" | ||
false | ||
elif test -f lib && test "$(cat lib)" != "hello" | ||
then | ||
echo "[OOPS] init failed but lib file was molested" | ||
false | ||
else | ||
rm lib | ||
fi | ||
' | ||
|
||
test_expect_success 'init should fail when path is used by a nonempty directory' ' | ||
mkdir lib && | ||
echo "hello" >lib/a && | ||
if git-submodule init | ||
then | ||
echo "[OOPS] init should have failed" | ||
false | ||
elif test "$(cat lib/a)" != "hello" | ||
then | ||
echo "[OOPS] init failed but lib/a was molested" | ||
false | ||
else | ||
rm lib/a | ||
fi | ||
' | ||
|
||
test_expect_success 'init should work when path is an empty dir' ' | ||
rm -rf lib && | ||
mkdir lib && | ||
git-submodule init && | ||
head=$(cd lib && git-rev-parse HEAD) && | ||
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 | ||
' | ||
|
||
test_expect_success 'status should be "up-to-date" after init' ' | ||
git-submodule status | grep "^ $rev1" | ||
' | ||
|
||
test_expect_success 'status should be "modified" after submodule commit' ' | ||
cd lib && | ||
echo b >b && | ||
git-add b && | ||
git-commit -m "submodule commit 2" && | ||
rev2=$(git-rev-parse HEAD) && | ||
cd .. && | ||
if test -z "$rev2" | ||
then | ||
echo "[OOPS] submodule git-rev-parse returned nothing" | ||
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 && | ||
head=$(cd lib && git-rev-parse HEAD) && | ||
if test -z "$head" | ||
then | ||
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' ' | ||
git-submodule status | grep "^ $rev1" | ||
' | ||
|
||
test_done |