summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-08-27 23:59:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-08-27 23:59:25 (GMT)
commitadc542353199bdc0b9b1ed5d03cf881b7efaff6e (patch)
tree8efb0498880322805bef23c4b71dd1a3bbd05c9d /git-submodule.sh
parentab36d06f12b7243de419bb82b11a678bea30eef2 (diff)
parente7fed18a89fae97655687e19f13cd802d8d70845 (diff)
downloadgit-adc542353199bdc0b9b1ed5d03cf881b7efaff6e.zip
git-adc542353199bdc0b9b1ed5d03cf881b7efaff6e.tar.gz
git-adc542353199bdc0b9b1ed5d03cf881b7efaff6e.tar.bz2
Merge branch 'jh/submodule-foreach'
* jh/submodule-foreach: git clone: Add --recursive to automatically checkout (nested) submodules t7407: Use 'rev-parse --short' rather than bash's substring expansion notation git submodule status: Add --recursive to recurse into nested submodules git submodule update: Introduce --recursive to update nested submodules git submodule foreach: Add --recursive to recurse into nested submodules git submodule foreach: test access to submodule name as '$name' Add selftest for 'git submodule foreach' git submodule: Cleanup usage string and add option parsing to cmd_foreach() git submodule foreach: Provide access to submodule name, as '$name' Conflicts: Documentation/git-submodule.txt git-submodule.sh
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh79
1 files changed, 71 insertions, 8 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 9bdd6ea..bfbd36b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,9 +4,14 @@
#
# Copyright (c) 2007 Lars Hjemli
-USAGE="[--quiet] [--cached|--files] \
-[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
-[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
+dashless=$(basename "$0" | sed -e 's/-/ /')
+USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> <path>
+ or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] init [--] [<path>...]
+ or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
+ or: $dashless [--quiet] foreach [--recursive] <command>
+ or: $dashless [--quiet] sync [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
. git-parse-remote
@@ -19,6 +24,7 @@ cached=
files=
nofetch=
update=
+prefix=
# Resolve relative url by appending to parent's url
resolve_relative_url ()
@@ -238,13 +244,43 @@ cmd_add()
#
cmd_foreach()
{
+ # parse $args after "submodule ... foreach".
+ while test $# -ne 0
+ do
+ case "$1" in
+ -q|--quiet)
+ GIT_QUIET=1
+ ;;
+ --recursive)
+ recursive=1
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+ done
+
module_list |
while read mode sha1 stage path
do
if test -e "$path"/.git
then
- say "Entering '$path'"
- (cd "$path" && eval "$@") ||
+ say "Entering '$prefix$path'"
+ name=$(module_name "$path")
+ (
+ 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
@@ -317,6 +353,7 @@ cmd_init()
cmd_update()
{
# parse $args after "submodule ... update".
+ orig_args="$@"
while test $# -ne 0
do
case "$1" in
@@ -349,6 +386,10 @@ cmd_update()
shift
update="merge"
;;
+ --recursive)
+ shift
+ recursive=1
+ ;;
--)
shift
break
@@ -435,6 +476,12 @@ cmd_update()
die "Unable to $action '$sha1' in submodule path '$path'"
say "Submodule path '$path': $msg '$sha1'"
fi
+
+ if test -n "$recursive"
+ then
+ (unset GIT_DIR; cd "$path" && cmd_update $orig_args) ||
+ die "Failed to recurse into submodule path '$path'"
+ fi
done
}
@@ -656,6 +703,7 @@ cmd_summary() {
cmd_status()
{
# parse $args after "submodule ... status".
+ orig_args="$@"
while test $# -ne 0
do
case "$1" in
@@ -665,6 +713,9 @@ cmd_status()
--cached)
cached=1
;;
+ --recursive)
+ recursive=1
+ ;;
--)
shift
break
@@ -684,22 +735,34 @@ cmd_status()
do
name=$(module_name "$path") || exit
url=$(git config submodule."$name".url)
+ displaypath="$prefix$path"
if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
then
- say "-$sha1 $path"
+ say "-$sha1 $displaypath"
continue;
fi
set_name_rev "$path" "$sha1"
if git diff-files --quiet -- "$path"
then
- say " $sha1 $path$revname"
+ say " $sha1 $displaypath$revname"
else
if test -z "$cached"
then
sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
set_name_rev "$path" "$sha1"
fi
- say "+$sha1 $path$revname"
+ say "+$sha1 $displaypath$revname"
+ fi
+
+ if test -n "$recursive"
+ then
+ (
+ prefix="$displaypath/"
+ unset GIT_DIR
+ cd "$path" &&
+ cmd_status $orig_args
+ ) ||
+ die "Failed to recurse into submodule path '$path'"
fi
done
}