From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Johan Herland <johan@herland.net>,
gitster@pobox.com, mlevedahl@gmail.com, hjemli@gmail.com
Subject: [RFC/PATCH 3/6] git submodule foreach: Provide access to submodule name, as '$name'
Date: Wed, 19 Aug 2009 03:45:21 +0200 [thread overview]
Message-ID: <1250646324-961-4-git-send-email-johan@herland.net> (raw)
In-Reply-To: <1250646324-961-1-git-send-email-johan@herland.net>
The argument to 'git submodule foreach' already has access to the variables
'$path' (the path to the submodule, relative to the superproject) and '$sha1'
(the submodule commit recorded by the superproject).
This patch adds another variable - '$name' - which contains the name of the
submodule, as recorded in the superproject's .gitmodules file.
Verification of the behaviour of '$name' is also added to the git submodule
foreach selftest.
Signed-off-by: Johan Herland <johan@herland.net>
---
This patch was initially sent stand-alone on 2009-08-16.
...Johan
Documentation/git-submodule.txt | 3 ++-
git-submodule.sh | 1 +
t/t7407-submodule-foreach.sh | 6 +++---
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index bb7d159..cfa8d73 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -135,7 +135,8 @@ summary::
foreach::
Evaluates an arbitrary shell command in each checked out submodule.
- The command has access to the variables $path and $sha1:
+ The command has access to the variables $name, $path and $sha1:
+ $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.
Any submodules defined in the superproject but not checked out are
diff --git a/git-submodule.sh b/git-submodule.sh
index c58eca4..6163d01 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -266,6 +266,7 @@ cmd_foreach()
if test -e "$path"/.git
then
say "Entering '$path'"
+ name=$(module_name "$path")
(cd "$path" && eval "$@") ||
die "Stopping at '$path'; script returned non-zero status."
fi
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 76e0734..991aa80 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -61,9 +61,9 @@ sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
cat > expect <<EOF
Entering 'sub1'
-sub1-$sub1sha1
+foo1-sub1-$sub1sha1
Entering 'sub3'
-sub3-$sub3sha1
+foo3-sub3-$sub3sha1
EOF
test_expect_success 'test basic "submodule foreach" usage' '
@@ -71,7 +71,7 @@ test_expect_success 'test basic "submodule foreach" usage' '
(
cd clone &&
git submodule update --init -- sub1 sub3 &&
- git submodule foreach "echo \$path-\$sha1" > ../actual
+ git submodule foreach "echo \$name-\$path-\$sha1" > ../actual
) &&
test_cmp expect actual
'
--
1.6.4.304.g1365c.dirty
next prev parent reply other threads:[~2009-08-19 1:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-19 1:45 [RFC/PATCH 0/6] Git submodule: 'foreach' enhancements and nested submodule handling Johan Herland
2009-08-19 1:45 ` [RFC/PATCH 1/6] git submodule: Cleanup usage string and add option parsing to cmd_foreach() Johan Herland
2009-08-19 1:45 ` [RFC/PATCH 2/6] Add selftest for 'git submodule foreach' Johan Herland
2009-08-19 1:45 ` Johan Herland [this message]
2009-08-19 1:45 ` [RFC/PATCH 4/6] git submodule foreach: Add --recursive to recurse into nested submodules Johan Herland
2009-08-19 1:45 ` [RFC/PATCH 5/6] git submodule update: Introduce --recursive to update " Johan Herland
2009-08-19 1:45 ` [RFC/PATCH 6/6] git submodule status: Add --recursive to recurse into " Johan Herland
2009-08-19 23:07 ` [RFC/PATCH 7/6] git clone: Add --recursive to automatically checkout (nested) submodules Johan Herland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1250646324-961-4-git-send-email-johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hjemli@gmail.com \
--cc=mlevedahl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).