summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2009-08-19 01:45:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-08-19 05:57:37 (GMT)
commit15fc56a853648c60697df691c5cd8a11ad718611 (patch)
treec5705bc5373e9d4552788ecb6decc60d279b7aa2 /git-submodule.sh
parent9aec7e0ba69334cf9bfc6bca6abbea7e84d676b2 (diff)
downloadgit-15fc56a853648c60697df691c5cd8a11ad718611.zip
git-15fc56a853648c60697df691c5cd8a11ad718611.tar.gz
git-15fc56a853648c60697df691c5cd8a11ad718611.tar.bz2
git submodule foreach: Add --recursive to recurse into nested submodules
In very large and hierarchically structured projects, one may encounter nested submodules. In these situations, it is valuable to not only operate on all the submodules in the current repo (which is what is currently done by 'git submodule foreach'), but also to operate on all submodules at all levels (i.e. recursing into nested submodules as well). This patch teaches the new --recursive option to the 'git submodule foreach' command. The patch also includes documentation and selftests. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh19
1 files changed, 16 insertions, 3 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index f48f682..c501b7e 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -10,7 +10,7 @@ USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> <p
or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--] [<path>...]
or: $dashless [--quiet] summary [--cached] [--summary-limit <n>] [commit] [--] [<path>...]
- or: $dashless [--quiet] foreach <command>
+ or: $dashless [--quiet] foreach [--recursive] <command>
or: $dashless [--quiet] sync [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
@@ -23,6 +23,7 @@ reference=
cached=
nofetch=
update=
+prefix=
# Resolve relative url by appending to parent's url
resolve_relative_url ()
@@ -249,6 +250,9 @@ cmd_foreach()
-q|--quiet)
GIT_QUIET=1
;;
+ --recursive)
+ recursive=1
+ ;;
-*)
usage
;;
@@ -264,9 +268,18 @@ cmd_foreach()
do
if test -e "$path"/.git
then
- say "Entering '$path'"
+ say "Entering '$prefix$path'"
name=$(module_name "$path")
- (cd "$path" && eval "$@") ||
+ (
+ prefix="$prefix$path/"
+ unset GIT_DIR
+ cd "$path" &&
+ eval "$@" &&
+ if test -n "$recursive"
+ then
+ cmd_foreach "--recursive" "$@"
+ fi
+ ) ||
die "Stopping at '$path'; script returned non-zero status."
fi
done