t7400: clarify submodule update tests

In particular, add a missing && to the update --init test.

The goal is to make it clearer what happened when one of these
tests fails.  The update --init test is currently (consistently)
failing on a few unusual machines.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder 2010-04-10 00:39:41 -05:00 committed by Junio C Hamano
parent a76c944bbe
commit ce8b54d676

View file

@ -28,9 +28,6 @@ test_expect_success 'setup - repository in init subdirectory' '
git commit -m "submodule commit 1" && git commit -m "submodule commit 1" &&
git tag -a -m "rev-1" rev-1 git tag -a -m "rev-1" rev-1
) )
rev1=$(cd init && git rev-parse HEAD) &&
printf "rev1: %s\n" "$rev1" &&
test -n "$rev1"
' '
test_expect_success 'setup - commit with gitlink' ' test_expect_success 'setup - commit with gitlink' '
@ -44,11 +41,6 @@ test_expect_success 'setup - hide init subdirectory' '
mv init .subrepo mv init .subrepo
' '
test_expect_success 'setup - add an example entry to .gitmodules' '
GIT_CONFIG=.gitmodules \
git config submodule.example.url git://example.com/init.git
'
test_expect_success 'setup - repository to add submodules to' ' test_expect_success 'setup - repository to add submodules to' '
git init addtest git init addtest
' '
@ -69,6 +61,7 @@ inspect() {
cd "$dir" && cd "$dir" &&
listbranches >"$dotdot/heads" && listbranches >"$dotdot/heads" &&
{ git symbolic-ref HEAD || :; } >"$dotdot/head" && { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
git rev-parse HEAD >"$dotdot/head-sha1" &&
git update-index --refresh && git update-index --refresh &&
git diff-files --exit-code && git diff-files --exit-code &&
git clean -n -d -x >"$dotdot/untracked" git clean -n -d -x >"$dotdot/untracked"
@ -181,131 +174,129 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
test_cmp empty untracked test_cmp empty untracked
' '
test_expect_success 'setup - add an example entry to .gitmodules' '
GIT_CONFIG=.gitmodules \
git config submodule.example.url git://example.com/init.git
'
test_expect_success 'status should fail for unmapped paths' ' test_expect_success 'status should fail for unmapped paths' '
if git submodule status test_must_fail git submodule status
then '
echo "[OOPS] submodule status succeeded"
false test_expect_success 'setup - map path in .gitmodules' '
elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init cat <<\EOF >expect &&
then [submodule "example"]
echo "[OOPS] git config failed to update .gitmodules" url = git://example.com/init.git
false path = init
fi EOF
GIT_CONFIG=.gitmodules git config submodule.example.path init &&
test_cmp expect .gitmodules
' '
test_expect_success 'status should only print one line' ' test_expect_success 'status should only print one line' '
lines=$(git submodule status | wc -l) && git submodule status >lines &&
test $lines = 1 test $(wc -l <lines) = 1
'
test_expect_success 'setup - fetch commit name from submodule' '
rev1=$(cd .subrepo && git rev-parse HEAD) &&
printf "rev1: %s\n" "$rev1" &&
test -n "$rev1"
' '
test_expect_success 'status should initially be "missing"' ' test_expect_success 'status should initially be "missing"' '
git submodule status | grep "^-$rev1" git submodule status >lines &&
grep "^-$rev1" lines
' '
test_expect_success 'init should register submodule url in .git/config' ' test_expect_success 'init should register submodule url in .git/config' '
echo git://example.com/init.git >expect &&
git submodule init && git submodule init &&
url=$(git config submodule.example.url) && git config submodule.example.url >url &&
if test "$url" != "git://example.com/init.git" git config submodule.example.url ./.subrepo &&
then
echo "[OOPS] init succeeded but submodule url is wrong" test_cmp expect url
false
elif test_must_fail git config submodule.example.url ./.subrepo
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' ' test_expect_success 'update should fail when path is used by a file' '
echo hello >expect &&
echo "hello" >init && echo "hello" >init &&
if git submodule update test_must_fail git submodule update &&
then
echo "[OOPS] update should have failed" test_cmp expect init
false
elif test "$(cat init)" != "hello"
then
echo "[OOPS] update failed but init file was molested"
false
else
rm init
fi
' '
test_expect_success 'update should fail when path is used by a nonempty directory' ' test_expect_success 'update should fail when path is used by a nonempty directory' '
echo hello >expect &&
rm -fr init &&
mkdir init && mkdir init &&
echo "hello" >init/a && echo "hello" >init/a &&
if git submodule update
then test_must_fail git submodule update &&
echo "[OOPS] update should have failed"
false test_cmp expect init/a
elif test "$(cat init/a)" != "hello"
then
echo "[OOPS] update failed but init/a was molested"
false
else
rm init/a
fi
' '
test_expect_success 'update should work when path is an empty dir' ' test_expect_success 'update should work when path is an empty dir' '
rm -rf init && rm -fr init &&
rm -f head-sha1 &&
echo "$rev1" >expect &&
mkdir init && mkdir init &&
git submodule update && git submodule update &&
head=$(cd init && git rev-parse HEAD) &&
if test -z "$head" inspect init &&
then test_cmp expect head-sha1
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 update' ' test_expect_success 'status should be "up-to-date" after update' '
git submodule status | grep "^ $rev1" git submodule status >list &&
grep "^ $rev1" list
' '
test_expect_success 'status should be "modified" after submodule commit' ' test_expect_success 'status should be "modified" after submodule commit' '
cd init && (
echo b >b && cd init &&
git add b && echo b >b &&
git commit -m "submodule commit 2" && git add b &&
rev2=$(git rev-parse HEAD) && git commit -m "submodule commit 2"
cd .. && ) &&
if test -z "$rev2"
then rev2=$(cd init && git rev-parse HEAD) &&
echo "[OOPS] submodule git rev-parse returned nothing" test -n "$rev2" &&
false git submodule status >list &&
fi &&
git submodule status | grep "^+$rev2" grep "^+$rev2" list
' '
test_expect_success 'the --cached sha1 should be rev1' ' test_expect_success 'the --cached sha1 should be rev1' '
git submodule --cached status | grep "^+$rev1" git submodule --cached status >list &&
grep "^+$rev1" list
' '
test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
git diff | grep "^+Subproject commit $rev2" git diff >diff &&
grep "^+Subproject commit $rev2" diff
' '
test_expect_success 'update should checkout rev1' ' test_expect_success 'update should checkout rev1' '
rm -f head-sha1 &&
echo "$rev1" >expect &&
git submodule update init && git submodule update init &&
head=$(cd init && git rev-parse HEAD) && inspect init &&
if test -z "$head"
then test_cmp expect head-sha1
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' ' test_expect_success 'status should be "up-to-date" after update' '
git submodule status | grep "^ $rev1" git submodule status >list &&
grep "^ $rev1" list
' '
test_expect_success 'checkout superproject with subproject already present' ' test_expect_success 'checkout superproject with subproject already present' '
@ -314,6 +305,8 @@ test_expect_success 'checkout superproject with subproject already present' '
' '
test_expect_success 'apply submodule diff' ' test_expect_success 'apply submodule diff' '
>empty &&
git branch second && git branch second &&
( (
cd init && cd init &&
@ -326,21 +319,24 @@ test_expect_success 'apply submodule diff' '
git format-patch -1 --stdout >P.diff && git format-patch -1 --stdout >P.diff &&
git checkout second && git checkout second &&
git apply --index P.diff && git apply --index P.diff &&
D=$(git diff --cached master) &&
test -z "$D" git diff --cached master >staged &&
test_cmp empty staged
' '
test_expect_success 'update --init' ' test_expect_success 'update --init' '
mv init init2 && mv init init2 &&
git config -f .gitmodules submodule.example.url "$(pwd)/init2" && git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
git config --remove-section submodule.example git config --remove-section submodule.example &&
test_must_fail git config submodule.example.url &&
git submodule update init > update.out && git submodule update init > update.out &&
cat update.out &&
grep "not initialized" update.out && grep "not initialized" update.out &&
test ! -d init/.git && ! test -d init/.git &&
git submodule update --init init && git submodule update --init init &&
test -d init/.git test -d init/.git
' '
test_expect_success 'do not add files from a submodule' ' test_expect_success 'do not add files from a submodule' '