Skip to content

Commit

Permalink
Merge branch 'ab/submodule-foreach-toplevel'
Browse files Browse the repository at this point in the history
* ab/submodule-foreach-toplevel:
  git-submodule foreach: Add $toplevel variable
  • Loading branch information
Junio C Hamano committed Jun 13, 2010
2 parents 5349308 + f030c96 commit 08b5687
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Documentation/git-submodule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ cmd_foreach()
shift
done

toplevel=$(pwd)

module_list |
while read mode sha1 stage path
do
Expand Down
10 changes: 7 additions & 3 deletions t/t7407-submodule-foreach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ 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' '
git clone super clone &&
(
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
'
Expand Down

0 comments on commit 08b5687

Please sign in to comment.