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

Re: GIT_DIR in aliases [Re: Spurious GIT_DIR set when in a worktree [was Re: Nested submodule status bug]

From
DRDamien Robert <damien.olivier.robert@gmail.com>
Date
Mar 3, 2020, 21:56 UTC
Message-ID
<20200303215650.vpsfgcjrsv42dqob@doriath>
In-Reply-To
<6D4FEE68-EF3C-491E-A7C1-3454B88977C3@gmail.com>
Show 5 quoted lines
> If that’s what your are trying to do, ‘git submodule foreach’ [1] seems like a better way to go. 
> For example I have an alias ‘st-sub’ that calls git status in the superproject and then recursively in the submodules:
> 
>     $ cat ~/.gitconfig | grep st-sub
>           st-sub = !git status "$@" && git sub foreach --recursive git status "$@"
I have almost the same aliases :)
	s = status --short --branch
	subfor="submodule foreach --recursive"
	subs="!f() { git subfor git s \"$@\";}; f"
	recs="!f() { git s \"$@\"; git subs \"$@\";}; f"
But in practice I often want to run commands only in *changed* submodules.
For instance with the above 'git subs' yields a lot of non informative
messages like:
  Entering 'non/changed/submodule'
  ## master...origin/master
(and git foreach --quiet) removes the first line but not the second.
This is also useful for an alias like 'recursive_commit' where I only want
to commit changed submodules, to not get a lot of messages like
     nothing to commit, working tree clean.

So I wrote a script that parses the output of 'git status --porcelain=v2' and run a command only in changed submodules (where I can specify if changed means 'C', 'M' or 'U'). Except that I did not think about unseting GIT_DIR and stumbled into this bug (I am sorry I went a bit on a wild chase in this mailing list but I had already spent quite some time in trying to find a minimal exemple, I first thought that my program had a parsing bug).

Now that I think about it, I probably also could do that with 'git submodule foreach', by testing 'git diff --no-ext-diff [--cached] --quiet' first before running the subcommand. This would give me the 'M' submodules, but it is not clear to me how I could test for 'C' changed submodules with this method.

-- 
Damien Robert
http://www.normalesup.org/~robert/pro
Previous: Philippe Blain
Message 13 of 13 in “Nested submodule checkout”
  1. Damien RobertFeb 14, 2020
  2. Philippe BlainFeb 17, 2020
  3. Damien RobertFeb 18, 2020
  4. Philippe BlainFeb 19, 2020
  5. Nested submodule status bugDamien Robert, Feb 26, 2020
  6. Damien RobertFeb 27, 2020
  7. Spurious GIT_DIR set when in a worktree [was Re: Nested submodule status bug]Damien Robert, Feb 27, 2020
  8. GIT_DIR in aliases [Re: Spurious GIT_DIR set when in a worktree [was Re: Nested submodule status bug]Damien Robert, Feb 27, 2020
  9. Jeff KingFeb 28, 2020
  10. Junio C HamanoFeb 28, 2020
  11. Damien RobertMar 3, 2020
  12. Philippe BlainFeb 29, 2020
  13. Damien RobertMar 3, 2020

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.