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

[PATCH] git submodule foreach: Provide access to submodule name, as '$name'

From
Johan Herland <johan@herland.net>
Date
Aug 16, 2009, 01:10 UTC
Message-ID
<200908160310.08459.johan@herland.net>

The argument to 'git submodule foreach' already has access to the variables '$path' (the path to the submodule, relative to the superproject) and '$sha1' (the submodule commit recorded by the superproject).

This patch adds another variable -- '$name' -- which contains the name of the submodule, as recorded in the superproject's .gitmodules file.

Signed-off-by: Johan Herland <johan@herland.net>
---
 Documentation/git-submodule.txt |    3 ++-
 git-submodule.sh                |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 7dd73ae..97c32fe 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -131,7 +131,8 @@ summary::
 
 foreach::
 	Evaluates an arbitrary shell command in each checked out submodule.
-	The command has access to the variables $path and $sha1:
+	The command has access to the variables $name, $path and $sha1:
+	$name is the name of the relevant submodule section in .gitmodules,
 	$path is the name of the submodule directory relative to the
 	superproject, and $sha1 is the commit as recorded in the superproject.
 	Any submodules defined in the superproject but not checked out are
diff --git a/git-submodule.sh b/git-submodule.sh
index ebed711..d8ecdb9 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -243,6 +243,7 @@ cmd_foreach()
 		if test -e "$path"/.git
 		then
 			say "Entering '$path'"
+			name=$(module_name "$path")
 			(cd "$path" && eval "$@") ||
 			die "Stopping at '$path'; script returned non-zero status."
 		fi
-- 
1.6.4.rc3.138.ga6b98.dirty
Next: Mark Levedahl
Message 1 of 2 in “git submodule foreach: Provide access to submodule name, as '$name'”
  1. git submodule foreach: Provide access to submodule name, as '$name'Johan Herland, Aug 16, 2009
  2. Mark LevedahlAug 18, 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.