threads / patch / 8337

patchAdd basic test-script for git-submodule

Subject: [PATCH] Add basic test-script for git-submodule

## tl;dr

9 messages between May 27, 2007 and Jun 2, 2007. Diffs are folded; open one to read it.

replies: 8people: 3as markdown or json

Lars Hjemli· May 27, 2007, 20:34 UTC · lore

This test verifies the basic operations in git-submodule, i.e. that it is able to clone and update a submodule repository, that its status output is sane, and that it errors out when the submodule path is occupied during init.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---

Finally the test-script emerges. Btw, thanks for fixing my broken submodule patch :)

 t/t7400-submodule-basic.sh |   82 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100755 t/t7400-submodule-basic.sh
Show changes to t/t7400-submodule-basic.sh +82 −0
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..2212b29
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='Basic submodule support in porcelain
+
+This test tries to run the init, update and status commands of git-submodule
+with a known good setup (and two known bad)
+'
+
+. ./test-lib.sh
+
+
+# create a submodule repository
+mkdir lib && cd lib
+git-init >/dev/null
+echo a >a && git-add a && git-commit -q -m "submodule commit 1"
+git-tag -a -m "rev-1" rev-1
+rev1=$(git-rev-parse HEAD)
+cd ..
+
+# add submodule and other files to super repo
+echo a >a && echo z >z
+git-add a lib z && git-commit -q -m "super commit 1"
+
+# move submodule to another location, register repo url in .gitmodules
+mv lib .subrepo
+GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+
+test_expect_success 'status is "missing"' \
+	'git-submodule status | grep "^-$rev1"'
+
+# make sure 'init' will not overwrite a regular file
+touch lib
+test_expect_failure 'init fails when path is used by a file' \
+	'git-submodule init'
+
+# make sure 'init' will not overwrite a nonempty directory
+rm lib
+mkdir -p lib/foo
+test_expect_failure 'init fails when path is used by a nonempty directory' \
+	'git-submodule init'
+
+# turn lib into an empty directory, just like git-checkout would do
+rmdir lib/foo
+test_expect_success 'init works when path is an empty dir' \
+	'git-submodule init && test -d lib/.git && git-diff --exit-code'
+
+head=$(cd lib && git-rev-parse HEAD)
+test_expect_success 'submodule HEAD should match rev1' \
+	'test "$head" = "$rev1"'
+
+test_expect_success 'status is "up-to-date" after init' \
+	'git-submodule status | grep "^ $rev1"'
+
+# change the submodule HEAD
+cd lib
+echo b >b && git-add b && git-commit -q -m "submodule commit 2"
+rev2=$(git-rev-parse HEAD)
+cd ..
+
+test_expect_success 'status is "modified" after submodule commit' \
+	'git-submodule status | grep "^\+$rev2"'
+
+test_expect_success 'the --cached sha1 should be rev1' \
+	'git-submodule --cached status | grep "^\+$rev1"'
+
+test_expect_failure 'git-diff --exit-code reports local modifications' \
+	'git-diff --exit-code'
+
+test_expect_success 'update should checkout the correct commit' \
+	'git-submodule update && git-diff --exit-code'
+
+head=$(cd lib && git-rev-parse HEAD)
+test_expect_success 'submodule HEAD should match rev1' \
+	'test "$head" = "$rev1"'
+
+test_expect_success 'status is "up-to-date" after update' \
+	'git-submodule status | grep "^ $rev1"'
+
+test_done
-- 
1.5.2.74.g6b2d
Junio C Hamano· May 29, 2007, 07:10 UTC · re: Lars Hjemli · lore

Re: [PATCH] Add basic test-script for git-submodule

Lars Hjemli <hjemli@gmail.com> writes:
Show 15 quoted lines
> +# create a submodule repository
> +mkdir lib && cd lib
> +git-init >/dev/null
> +echo a >a && git-add a && git-commit -q -m "submodule commit 1"
> +git-tag -a -m "rev-1" rev-1
> +rev1=$(git-rev-parse HEAD)
> +cd ..
> +
> +# add submodule and other files to super repo
> +echo a >a && echo z >z
> +git-add a lib z && git-commit -q -m "super commit 1"
> +
> +# move submodule to another location, register repo url in .gitmodules
> +mv lib .subrepo
> +GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
We typically try to catch malfunction even while setting up the test case.
Show 7 quoted lines
> +test_expect_success 'status is "missing"' \
> +	'git-submodule status | grep "^-$rev1"'
> +
> +# make sure 'init' will not overwrite a regular file
> +touch lib
> +test_expect_failure 'init fails when path is used by a file' \
> +	'git-submodule init'

I am guilty for introducing "expect-failure", but it is usually a mistake to use it unless you are testing something very trivial.

For example, for this case, you would want to make sure the command "git-submodule init" exits with non-zero status, but also you would want to make sure that it does not disturb the existing file "lib". You might also want to see if the command gives the right error message (or status code) as well, although typically the wording of error message is subject to change, so we tend to try not to be too strict about it.

In any case, I would probably write this part of the code like this:

        test_expect_success 'init fails when path is used by a file' '
                echo hello >lib &&
                if git-submodule init
                then
                        echo "Oops, should have failed"
                        false
                elif test -f lib && test "$(cat lib)" = hello
                then		
                        : happy
                else
                        echo "Oops, failed but lib file was molested"
                        false
                fi
        '

Later when somebody tries to improve git-submodule and botches, he can run the test with "-i -v" and observe which "Oops" comes out to see why the test failed -- it would give him a clue on how he broke it.

Lars Hjemli· May 30, 2007, 06:48 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add basic test-script for git-submodule

On 5/29/07, Junio C Hamano <junkio@cox.net> wrote:
Show 19 quoted lines
> Lars Hjemli <hjemli@gmail.com> writes:
>
> > +# create a submodule repository
> > +mkdir lib && cd lib
> > +git-init >/dev/null
> > +echo a >a && git-add a && git-commit -q -m "submodule commit 1"
> > +git-tag -a -m "rev-1" rev-1
> > +rev1=$(git-rev-parse HEAD)
> > +cd ..
> > +
> > +# add submodule and other files to super repo
> > +echo a >a && echo z >z
> > +git-add a lib z && git-commit -q -m "super commit 1"
> > +
> > +# move submodule to another location, register repo url in .gitmodules
> > +mv lib .subrepo
> > +GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
>
> We typically try to catch malfunction even while setting up the test case.
Ok
Show 16 quoted lines
>
> > +test_expect_success 'status is "missing"' \
> > +     'git-submodule status | grep "^-$rev1"'
> > +
> > +# make sure 'init' will not overwrite a regular file
> > +touch lib
> > +test_expect_failure 'init fails when path is used by a file' \
> > +     'git-submodule init'
>
> I am guilty for introducing "expect-failure", but it is usually
> a mistake to use it unless you are testing something very trivial.
>
> For example, for this case, you would want to make sure the
> command "git-submodule init" exits with non-zero status, but
> also you would want to make sure that it does not disturb the
> existing file "lib".

Would you prefer a patch on top of this version of the test-script or on top of the later patch which uses .git/config to store submodule url?

-- larsh

Junio C Hamano· Jun 1, 2007, 03:54 UTC · re: Lars Hjemli · lore

Re: [PATCH] Add basic test-script for git-submodule

"Lars Hjemli" <hjemli@gmail.com> writes:
> Would you prefer a patch on top of this version of the test-script or
> on top of the later patch which uses .git/config to store submodule
> url?

As you said you will be redoing submodule + .git/config stuff in your other message, I would expect a replacement (i.e. not on top of this) patch for tests to check the existing submodule features. If you want to finish the submodule + .git/config one first and then test script on top to test both existing featues and submodule + .git/config features, that is fine as well. Your choice.

One important point is to treat the test-script take #1 as "already rejected", and not basing further patches on it.

Lars Hjemli· Jun 1, 2007, 07:10 UTC · re: Junio C Hamano · lore

Re: [PATCH] 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>
---
On 6/1/07, Junio C Hamano <junkio@cox.net> wrote:
Show 7 quoted lines
> As you said you will be redoing submodule + .git/config stuff in
> your other message, I would expect a replacement (i.e. not on
> top of this) patch for tests to check the existing submodule
> features.  If you want to finish the submodule + .git/config one
> first and then test script on top to test both existing featues
> and submodule + .git/config features, that is fine as well.
> Your choice.

My continuous quest for self-discipline left me no choice but to attempt the creation of a proper testscript for the existing features ;-)

  t/t7400-submodule-basic.sh |  143 ++++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 143 insertions(+), 0 deletions(-)
  create mode 100755 t/t7400-submodule-basic.sh
Show changes to t/t7400-submodule-basic.sh +143 −0
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..a8beee2
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -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
-- 
1.5.2.839.ga3b1-dirty
Johannes Sixt· Jun 1, 2007, 07:56 UTC · re: Lars Hjemli · lore

Re: [PATCH] Add basic test-script for git-submodule

Lars Hjemli wrote:
> +test_expect_success 'status should only print one line' '
> +       lines=$(git-submodule status | wc -l)
&& is missing.
> +       test "$lines" = "1"

Please don't put output of wc in quotes because some versions of wc emit padding:

	test $lines = 1
(without the quotes around 1 - like in other test scripts).
-- Hannes
Lars Hjemli· Jun 1, 2007, 08:13 UTC · re: Johannes Sixt · lore

Re: [PATCH] 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>
---
On Fri, 01 Jun 2007 09:56:12 +0200, Johannes Sixt <J.Sixt@eudaptics.com> wrote:
Show 15 quoted lines
> Lars Hjemli wrote:
>> +test_expect_success 'status should only print one line' '
>> +       lines=$(git-submodule status | wc -l)
>
> && is missing.
>
>> +       test "$lines" = "1"
>
> Please don't put output of wc in quotes because some versions of wc emit
> padding:
>
> 	test $lines = 1
>
> (without the quotes around 1 - like in other test scripts).
>
Thanks, and sorry...
  t/t7400-submodule-basic.sh |  143 ++++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 143 insertions(+), 0 deletions(-)
  create mode 100755 t/t7400-submodule-basic.sh
Show changes to t/t7400-submodule-basic.sh +143 −0
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..a985a6e
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -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
-- 
1.5.2.839.ga3b1-dirty
Junio C Hamano· Jun 1, 2007, 19:50 UTC · re: Lars Hjemli · lore

Re: [PATCH] Add basic test-script for git-submodule

"Lars Hjemli" <hjemli@gmail.com> writes:
Show 5 quoted lines
> 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>
Micronit...
> +test_expect_success 'the --cached sha1 should be rev1' '
> +	git-submodule --cached status | grep "^\+$rev1"
> +'
What's the purpose of that solitary backslash?
Lars Hjemli· Jun 2, 2007, 01:27 UTC · re: Junio C Hamano · lore

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>
---
On 6/1/07, Junio C Hamano <junkio@cox.net> wrote:
Show 6 quoted lines
> "Lars Hjemli" <hjemli@gmail.com> writes:
> > +test_expect_success 'the --cached sha1 should be rev1' '
> > +     git-submodule --cached status | grep "^\+$rev1"
> > +'
> 
> What's the purpose of that solitary backslash?

That's just a sign of me being sloppy, expecting the behaviour of 'grep -E' without bothering to study the man-page. Sorry.

 t/t7400-submodule-basic.sh |  143 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100755 t/t7400-submodule-basic.sh
Show changes to t/t7400-submodule-basic.sh +143 −0
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..6274729
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -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
-- 
1.5.2.839.ga3b1-dirty

← back to recent threads