1
0
mirror of https://github.com/git/git.git synced 2025-04-11 08:56:12 +00:00

Merge branch 'ab/submodule-foreach-toplevel'

* ab/submodule-foreach-toplevel:
  git-submodule foreach: Add $toplevel variable
This commit is contained in:
Junio C Hamano 2010-06-13 11:21:49 -07:00
commit 08b56871ff
3 changed files with 13 additions and 5 deletions

@ -145,10 +145,12 @@ summary::
foreach::
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.

@ -271,6 +271,8 @@ cmd_foreach()
shift
done
toplevel=$(pwd)
module_list |
while read mode sha1 stage path
do

@ -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)
pwd=$(pwd)
cat > expect <<EOF
Entering 'sub1'
foo1-sub1-$sub1sha1
$pwd/clone-foo1-sub1-$sub1sha1
Entering 'sub3'
foo3-sub3-$sub3sha1
$pwd/clone-foo3-sub3-$sub3sha1
EOF
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 foo.bar zar &&
git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar"
) &&
test_cmp expect actual
'