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

Re: [PATCH] git-submodule add: Record branch name in .gitmodules

From
Phil Hord <phil.hord@gmail.com>
Date
Oct 24, 2012, 18:12 UTC
Message-ID
<CABURp0rpPqeTJMYXmgMG2CmU=SzzvCMeX46rnMVB0EeB_LXPiA@mail.gmail.com>
In-Reply-To
<20121022225546.GO23101@odin.tremily.us>
On Mon, Oct 22, 2012 at 6:55 PM, W. Trevor King <wking@tremily.us> wrote:
Show 13 quoted lines
> 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"
Previous: W. Trevor KingNext: W. Trevor King
Message 10 of 12 in “git-submodule add: Record branch name in .gitmodules”
  1. git-submodule add: Record branch name in .gitmodulesW. Trevor King, Oct 22, 2012
  2. NahorOct 23, 2012
  3. W. Trevor KingOct 23, 2012
  4. NahorOct 23, 2012
  5. Jens LehmannOct 23, 2012
  6. W. Trevor KingOct 23, 2012
  7. NahorOct 23, 2012
  8. Jens LehmannOct 24, 2012
  9. W. Trevor KingOct 22, 2012
  10. Phil HordOct 24, 2012
  11. W. Trevor KingOct 25, 2012
  12. Jeff KingOct 26, 2012

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.