Browse Source

Merge branch 'ab/submodule-foreach-toplevel'

* ab/submodule-foreach-toplevel:
  git-submodule foreach: Add $toplevel variable
maint
Junio C Hamano 15 years ago
parent
commit
08b56871ff
  1. 6
      Documentation/git-submodule.txt
  2. 2
      git-submodule.sh
  3. 10
      t/t7407-submodule-foreach.sh

6
Documentation/git-submodule.txt

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

2
git-submodule.sh

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

toplevel=$(pwd)

module_list |
while read mode sha1 stage path
do

10
t/t7407-submodule-foreach.sh

@ -59,11 +59,13 @@ test_expect_success 'setup a submodule tree' ' @@ -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' ' @@ -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
'

Loading…
Cancel
Save