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
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Feb 29, 2020, 01:42 UTC
Message-ID
<6D4FEE68-EF3C-491E-A7C1-3454B88977C3@gmail.com>
In-Reply-To
<20200227155057.7idpa447ixo6sf6j@feanor>
Hi Damien,
Show 5 quoted lines
> Le 27 févr. 2020 à 10:50, Damien Robert <damien.olivier.robert@gmail.com> a écrit :
> 
> So one might argue that the behaviour I observed is not a bug, but it is
> still surprising for me (as a user), and maybe this could be stated more
> clearly in the docs?
It sure is surprising, and not super intuitive.
Show 10 quoted lines
> 
> Furthermore there is a question of consistency. GIT_DIR will not always be set
> before running a shell alias. Looking at `setup_discovered_git_dir`, it will
> be set if we are in a bare dir, or core.worktree / WORK_TREE is set, or if
> we have a gitfile.
> 
> The annoying side effect is that I cannot use as an alias a command that
> iterate over submodules and run git commands inside them, because in this
> alias GIT_DIR will be set sometimes, and sometimes not (a quick fix would be to
> unset GIT_DIR in my alias).

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 "$@"
[1] https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-foreach--recursiveltcommandgt
> 
> So what would be the best way to handle this?
> Thanks,
> Damien

Cheers, Philippe.

Previous: Damien RobertNext: Damien Robert
Message 12 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.