Petr Baudis provided good feedback on the list, leading to this patch to modify foreach. This clarifies that the input to "foreach" is a single shell command, though internally foreach evaluates "$@" so *may* work even if the user fails to enclose the command in quotes. Also, this adds output of each submodule entered unless --quiet is given, providing feedback at the command line but still allowing a script to precisely control the output given. Signed-off-by: Mark Levedahl <mlevedahl@xxxxxxxxx> --- Documentation/git-submodule.txt | 12 +++++++----- git-submodule.sh | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 3470795..abbd5b7 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -14,7 +14,7 @@ SYNOPSIS 'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] update [--init] [--] [<path>...] 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...] -'git submodule' foreach <command-list> +'git submodule' [--quiet] foreach <command> DESCRIPTION @@ -125,14 +125,16 @@ summary:: index or working tree (switched by --cached) are shown. foreach:: - Executes an arbitrary list of commands in each checked out submodule. + Evaluates an arbitrary shell command in each checked out submodule. + The command has access to the variables $path and $sha1: $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 - ignored by this command, and an empty command-list provides no output. - A non-zero return from the command-list in any submodule causes + ignored by this command. Unless given --quiet, foreach prints the name + of each submodule before evaluating the command. + A non-zero return from the command in any submodule causes the processing to terminate. This can be overridden by adding '|| :' - to the end of the command list. + to the end of the command. + As an example, "git submodule foreach 'echo $path `git rev-parse HEAD`' will show the path and currently checked out commit for each submodule. diff --git a/git-submodule.sh b/git-submodule.sh index fc41e59..2d57d60 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>...]|[foreach <command-list>]" +[--] [<path>...]|[foreach <command>]" OPTIONS_SPEC= . git-sh-setup require_work_tree @@ -211,6 +211,7 @@ cmd_foreach() do if test -e "$path"/.git then + say "Entering '$path'" (cd "$path" && eval "$@") || die "Stopping at '$path'; script returned non-zero status." fi -- 1.6.0.rc2.45.g1363 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html