diff options
3 files changed, 13 insertions, 5 deletions
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 2502531..cdabfd2 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -145,10 +145,12 @@ summary::
Evaluates an arbitrary shell command in each checked out submodule.
- The command has access to the variables $name, $path and $sha1:
+ The command has access to the variables $name, $path, $sha1 and
+ $toplevel:
$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.
+ superproject, $sha1 is the commit as recorded in the superproject,
+ and $toplevel is the absolute path to the top-level of the superproject.
Any submodules defined in the superproject but not checked out are
ignored by this command. Unless given --quiet, foreach prints the name
of each submodule before evaluating the command.
diff --git a/ b/
index 8175cb2..8c562a7 100755
--- a/
+++ b/
@@ -271,6 +271,8 @@ cmd_foreach()
+ toplevel=$(pwd)
module_list |
while read mode sha1 stage path
diff --git a/t/ b/t/
index 2a52775..db9365b 100755
--- a/t/
+++ b/t/
@@ -59,11 +59,13 @@ test_expect_success 'setup a submodule tree' '
sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
cat > expect <<EOF
Entering 'sub1'
Entering 'sub3'
test_expect_success 'test basic "submodule foreach" usage' '
@@ -71,7 +73,9 @@ test_expect_success 'test basic "submodule foreach" usage' '
cd clone &&
git submodule update --init -- sub1 sub3 &&
- git submodule foreach "echo \$name-\$path-\$sha1" > ../actual
+ git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual &&
+ git config zar &&
+ git submodule foreach "git config --file \"\$toplevel/.git/config\""
) &&
test_cmp expect actual