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

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

From
DRDamien Robert <damien.olivier.robert@gmail.com>
Date
Feb 27, 2020, 10:43 UTC
Message-ID
<20200227104330.hp7zf2suquxsf6zw@feanor>
In-Reply-To
<20200227100557.ydouc4n3jphzbits@feanor>
Show 8 quoted lines
> Ok, so using GIT_TRACE and GIT_TRACE_STATUS and doing some debugging I
> understand the cause of the bug. When using the alias,
> the GIT_DIR environment is set to the bar module:
>     GIT_DIR=/tmp/test/foo/.git/modules/bar
> and is exported.
> 
> That's explain why in `baz` the status report the status of the `bar`
> directory.

And looking at setup.c:760 it appears that `set_git_dir` (which set up among other things the GIT_DIR env) is called because we are in a worktree.

More precisely: we have discovered a git dir (a git file), so we call setup_discovered_git_dir, which itself calls setup_explicit_git_dir because we are in a work tree environment. And set_up_explicit_git_dir calls set_git_dir.

So I don't know what's the proper way to fix this. Keep track when we add ourselves the GIT_DIR rather than when it is already provided and remove it before executing a shell alias? Don't run the full configuration setup when we are executing a shell alias anyway?

I am adding Nguyễn Thái Ngọc Duy to the discussion (I hope this is the proper etiquette).

Best regards, Damien

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