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, 22:44 UTC
Message-ID
<20200303224430.c64dmvzr4c72f2tv@doriath>
In-Reply-To
<20200228190218.GC1408759@coredump.intra.peff.net>
From Jeff King, Fri 28 Feb 2020 at 14:02:18 (-0500) :
> > 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.
> We were discussing the same issue recently with regards to hooks. See:
>   https://lore.kernel.org/git/20200130102933.GE840531@coredump.intra.peff.net/
> and the responses. I think we could do better, but at the cost of
> breaking a relatively obscure git-clone feature.

Yes I found this discussion afterwards. This is related but a bit different, the problem you discuss is that GIT_WORK_TREE is not always set even when GIT_DIR is. The problem I have is that GIT_DIR is not always set; it depends on the phase of the moon (are we in a worktree? ...), which makes things that forget to unset it half broken and hard to debug.

I would argue that for scripts and hooks we should always set both. This is easy to do (at least for scripts, I haven't looked at hooks) without touching at setup_discovered_git_dir, so not affecting git clone.

In fact I would even argue that in setup_discovered_git_dir we should always set both, and fix the breakages that appear, like the one you mention for git clone. For instance I wonder if the recent report about 'git gui' setting GIT_DIR is not due to this.

> Note there are other variables you might want to unset, too, if you're
> switching repositories. Doing:
>   unset $(git rev-parse --local-env-vars)
> would cover the full list.
Thanks for the hint; I had forgotten about local-env-vars.
Previous: Junio C HamanoNext: Philippe Blain
Message 11 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.