git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Johan HerlandNext: Mark Levedahl
Message 3 of 10 in “git-submodule - Add 'foreach' subcommand”
  1. git-submodule - Add 'foreach' subcommandMark Levedahl, Aug 10, 2008
  2. Johan HerlandAug 10, 2008
  3. Junio C HamanoAug 10, 2008
  4. git-submodule - Add 'foreach' subcommandMark Levedahl, Aug 10, 2008
  5. Balazs NagyAug 11, 2008
  6. Johannes SchindelinAug 11, 2008
  7. Matthias KestenholzAug 11, 2008
  8. Petr BaudisAug 11, 2008
  9. Junio C HamanoAug 11, 2008
  10. git-submodule foreach - Include output and clarify usage.Mark Levedahl, Aug 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.