Re: [PATCH] git-submodule - Add 'foreach' subcommand
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 10, 2008, 22:37 UTC
- Message-ID
- <7vsktczebg.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <1218386647-2348-1-git-send-email-mlevedahl@gmail.com>
Mark Levedahl <mlevedahl@gmail.com> writes:
> 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.
Thanks for keeping the topic going
Show 9 quoted lines
> +foreach:: > + Executes an arbitrary list of commands in each checked out submodule. > + $path is the name of the submodule directory relative to the > + superproject, and $sha1 is the commit as recorded in the superproject. > + And submodules defined in the superproject but not checked out are > + ignored by this command, and an empty command-list provides no output. > ++ > +As an example, "git submodule foreach 'echo $path `git rev-parse HEAD`' will > +show the path and currently checked out commit for each submodule.
I think this is a sensible building block to have.
Show 11 quoted lines
> +cmd_foreach()
> +{
> + git ls-files --stage | grep '^160000 ' |
> + while read mode sha1 stage path
> + do
> + if test -e "$path"/.git
> + then
> + (cd "$path" && eval "$@")
> + fi
> + done
> +}I suspect we may want to stop the loop upon failure from eval (any user that wants to run command in all submodules no matter what could add '||:' to the cmd list), but other than that this is a simple enough and good addition.