aboutsummaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorMark Levedahl <mlevedahl@gmail.com>2008-08-10 19:10:04 -0400
committerJunio C Hamano <gitster@pobox.com>2008-08-17 16:29:22 -0700
commit19a31f9c1a6b18abd8a7f20d616516afca36a6a3 (patch)
tree1ff73361b6b1374724b86bbdedef7f5d750c2bac /git-submodule.sh
parent2ebc02d32a4360da2cf69c2b5f5bfad0716d42b0 (diff)
downloadgit-19a31f9c1a6b18abd8a7f20d616516afca36a6a3.tar.gz
git-19a31f9c1a6b18abd8a7f20d616516afca36a6a3.tar.xz
git-submodule - Add 'foreach' subcommand
submodule foreach <command-list> will execute the list of commands in each currently checked out submodule directory. The list of commands is arbitrary as long as it is acceptable to sh. The variables '$path' and '$sha1' are availble to the command-list, defining the submodule path relative to the superproject and the submodules's commitID as recorded in the superproject (this may be different than HEAD in the submodule). This utility is inspired by a number of threads on the mailing list looking for ways to better integrate submodules in a tree and work with them as a unit. This could include fetching a new branch in each from a given source, or possibly checking out a given named branch in each. Currently, there is no consensus as to what additional commands should be implemented in the porcelain, requiring all users whose needs exceed that of git-submodule to do their own scripting. The foreach command is intended to support such scripting, and in particular does no error checking and produces no output, thus allowing end users complete control over any information printed out and over what constitutes an error. The processing does terminate if the command-list returns an error, but processing can easily be forced for all submodules be terminating the list with ';true'. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh24
1 files changed, 22 insertions, 2 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index b40f876a2..2d57d6045 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -6,7 +6,7 @@
USAGE="[--quiet] [--cached] \
[add <repo> [-b branch] <path>]|[status|init|update [-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
-[--] [<path>...]"
+[--] [<path>...]|[foreach <command>]"
OPTIONS_SPEC=
. git-sh-setup
require_work_tree
@@ -199,6 +199,26 @@ cmd_add()
}
#
+# Execute an arbitrary command sequence in each checked out
+# submodule
+#
+# $@ = command to execute
+#
+cmd_foreach()
+{
+ git ls-files --stage | grep '^160000 ' |
+ while read mode sha1 stage path
+ do
+ if test -e "$path"/.git
+ then
+ say "Entering '$path'"
+ (cd "$path" && eval "$@") ||
+ die "Stopping at '$path'; script returned non-zero status."
+ fi
+ done
+}
+
+#
# Register submodules in .git/config
#
# $@ = requested paths (default to all)
@@ -583,7 +603,7 @@ cmd_status()
while test $# != 0 && test -z "$command"
do
case "$1" in
- add | init | update | status | summary)
+ add | foreach | init | update | status | summary)
command=$1
;;
-q|--quiet)