Merge branch 'ab/submodule-foreach-toplevel'

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

View File

@ -145,10 +145,12 @@ summary::


foreach:: foreach::
Evaluates an arbitrary shell command in each checked out submodule. 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, $name is the name of the relevant submodule section in .gitmodules,
$path is the name of the submodule directory relative to the $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 Any submodules defined in the superproject but not checked out are
ignored by this command. Unless given --quiet, foreach prints the name ignored by this command. Unless given --quiet, foreach prints the name
of each submodule before evaluating the command. of each submodule before evaluating the command.

View File

@ -271,6 +271,8 @@ cmd_foreach()
shift shift
done done


toplevel=$(pwd)

module_list | module_list |
while read mode sha1 stage path while read mode sha1 stage path
do do

View File

@ -59,11 +59,13 @@ test_expect_success 'setup a submodule tree' '
sub1sha1=$(cd super/sub1 && git rev-parse HEAD) sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
sub3sha1=$(cd super/sub3 && git rev-parse HEAD) sub3sha1=$(cd super/sub3 && git rev-parse HEAD)


pwd=$(pwd)

cat > expect <<EOF cat > expect <<EOF
Entering 'sub1' Entering 'sub1'
foo1-sub1-$sub1sha1 $pwd/clone-foo1-sub1-$sub1sha1
Entering 'sub3' Entering 'sub3'
foo3-sub3-$sub3sha1 $pwd/clone-foo3-sub3-$sub3sha1
EOF EOF


test_expect_success 'test basic "submodule foreach" usage' ' test_expect_success 'test basic "submodule foreach" usage' '
@ -71,7 +73,9 @@ test_expect_success 'test basic "submodule foreach" usage' '
( (
cd clone && cd clone &&
git submodule update --init -- sub1 sub3 && 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 test_cmp expect actual
' '