Skip to contentSkip to conversation

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

PATCH In review Johan Herland 2 participants 2 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git submodule foreach: Provide access to submodule name, as '$name'

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.

---
 Documentation/git-submodule.txt |    3 ++-
 git-submodule.sh                |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)
Documentation/git-submodule.txt +2 -1
index 7dd73ae..97c32fe 100644
@@ -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
git-submodule.sh +1 -0
index ebed711..d8ecdb9 100755
@@ -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
Signature · 1 line
1.6.4.rc3.138.ga6b98.dirty
#1 lore raw
Quoted 10 lines · Johan Herland

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.

---

This patch *looks* ok to me, but I'm out of the office for most of August so I cannot actually test this code for another couple of weeks.

Mark