Re: [PATCH] git-submodule - Add 'foreach' subcommand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mark Levedahl <mlevedahl@xxxxxxxxx> 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

> +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.

> +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.

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux