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

[RFC/PATCH 2/6] Add selftest for 'git submodule foreach'

From
Johan Herland <johan@herland.net>
Date
Aug 19, 2009, 01:45 UTC
Message-ID
<1250646324-961-3-git-send-email-johan@herland.net>
In-Reply-To
<1250646324-961-1-git-send-email-johan@herland.net>
The selftest verifies that:
- only checked out submodules are visited by 'git submodule foreach'
- the $path, and $sha1 variables are set correctly for each submodule
Signed-off-by: Johan Herland <johan@herland.net>
---
 t/t7407-submodule-foreach.sh |   79 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)
 create mode 100755 t/t7407-submodule-foreach.sh
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
new file mode 100755
index 0000000..76e0734
--- /dev/null
+++ b/t/t7407-submodule-foreach.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Johan Herland
+#
+
+test_description='Test "git submodule foreach"
+
+This test verifies that "git submodule foreach" correctly visits all submodules
+that are currently checked out.
+'
+
+. ./test-lib.sh
+
+
+test_expect_success 'setup a submodule tree' '
+	echo file > file &&
+	git add file &&
+	test_tick &&
+	git commit -m upstream
+	git clone . super &&
+	git clone super submodule &&
+	(
+		cd super &&
+		git submodule add ../submodule sub1 &&
+		git submodule add ../submodule sub2 &&
+		git submodule add ../submodule sub3 &&
+		git config -f .gitmodules --rename-section \
+			submodule.sub1 submodule.foo1 &&
+		git config -f .gitmodules --rename-section \
+			submodule.sub2 submodule.foo2 &&
+		git config -f .gitmodules --rename-section \
+			submodule.sub3 submodule.foo3 &&
+		git add .gitmodules
+		test_tick &&
+		git commit -m "submodules" &&
+		git submodule init sub1 &&
+		git submodule init sub2 &&
+		git submodule init sub3
+	) &&
+	(
+		cd submodule &&
+		echo different > file &&
+		git add file &&
+		test_tick &&
+		git commit -m "different"
+	) &&
+	(
+		cd super &&
+		(
+			cd sub3 &&
+			git pull
+		) &&
+		git add sub3 &&
+		test_tick &&
+		git commit -m "update sub3"
+	)
+'
+
+sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
+sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
+
+cat > expect <<EOF
+Entering 'sub1'
+sub1-$sub1sha1
+Entering 'sub3'
+sub3-$sub3sha1
+EOF
+
+test_expect_success 'test basic "submodule foreach" usage' '
+	git clone super clone &&
+	(
+		cd clone &&
+		git submodule update --init -- sub1 sub3 &&
+		git submodule foreach "echo \$path-\$sha1" > ../actual
+	) &&
+	test_cmp expect actual
+'
+
+test_done
-- 
1.6.4.304.g1365c.dirty
Previous: Johan HerlandNext: Johan Herland
Message 3 of 8 in “Git submodule: 'foreach' enhancements and nested submodule handling”
  1. 0/6 Git submodule: 'foreach' enhancements and nested submodule handlingJohan Herland, Aug 19, 2009
  2. 1/6 git submodule: Cleanup usage string and add option parsing to cmd_foreach()Johan Herland, Aug 19, 2009
  3. 2/6 Add selftest for 'git submodule foreach'Johan Herland, Aug 19, 2009
  4. 3/6 git submodule foreach: Provide access to submodule name, as '$name'Johan Herland, Aug 19, 2009
  5. 4/6 git submodule foreach: Add --recursive to recurse into nested submodulesJohan Herland, Aug 19, 2009
  6. 5/6 git submodule update: Introduce --recursive to update nested submodulesJohan Herland, Aug 19, 2009
  7. 6/6 git submodule status: Add --recursive to recurse into nested submodulesJohan Herland, Aug 19, 2009
  8. 7/6 git clone: Add --recursive to automatically checkout (nested) submodulesJohan Herland, Aug 19, 2009

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.