git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
LHLars Hjemli <hjemli@gmail.com>
Date
May 27, 2007, 20:34 UTC
Message-ID
<11802980992216-git-send-email-hjemli@gmail.com>

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
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
Next: Junio C Hamano
Message 1 of 9 in “Add basic test-script for git-submodule”
  1. Add basic test-script for git-submoduleLars Hjemli, May 27, 2007
  2. Junio C HamanoMay 29, 2007
  3. Lars HjemliMay 30, 2007
  4. Junio C HamanoJun 1, 2007
  5. Lars HjemliJun 1, 2007
  6. Johannes SixtJun 1, 2007
  7. Lars HjemliJun 1, 2007
  8. Junio C HamanoJun 1, 2007
  9. Add basic test-script for git-submoduleLars Hjemli, Jun 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.