Re: [PATCH] git-submodule add: Record branch name in .gitmodules
flat view
From: Phil Hord <hidden>
Date: 2016-06-15 22:55:06
On Mon, Oct 22, 2012 at 6:55 PM, W. Trevor King [off-list ref] wrote:
On a tangentially related note, it would be nice to set environment
variables for each of the settings in submodule.$name during a foreach
call. Then you could use
git submodule foreach 'git checkout $branch && git pull'
Perhaps you'd want to blacklist/whitelist or downcase settings names
to avoid things like
[submodule "foo"]
PATH = /my/rootkit/
but the update line is much cleaner.This is ugly as can be, but it works in my meagre testing. It defines "submodule_path=/my/rootkit/" for the above bit of .gitmodules. That is, it adds definitions for 'submodule_<var-name>' for each <var-name> in .gitmodules in submodule.$name.<var-name>, but <var-name> is lowercased and defanged (everything that's not already [a-z0-9] is replaced with underscore). For example, git submodule foreach 'echo $submodule_url'
--- >8 ---
diff --git c/git-submodule.sh i/git-submodule.sh
index 6dd2338..79b3467 100755
--- c/git-submodule.sh
+++ i/git-submodule.sh@@ -416,7 +416,15 @@ cmd_foreach() prefix="$prefix$sm_path/" clear_local_git_env # we make $path available to scripts ... path=$sm_path + + # make all submodule variables
available to scripts
+ eval $(git config -f .gitmodules
--get-regexp "^submodule\.${name}\..*" |
+ sed -e "s|^submodule\.${name}\.||" |
+ while read VAR_NAME VAR_VALUE ; do
+ VAR_NAME=$(printf '%s'
"$VAR_NAME" | tr A-Z a-z | sed -e 's/^[^a-z]/_/' -e 's/[^a-z0-9]/_/g')
+ printf 'submodule_%s=%s;\n'
"$VAR_NAME" "'$VAR_VALUE'"
+ done)
cd "$sm_path" &&
eval "$@" &&
if test -n "$recursive"