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

Re: [PATCH] allow setting GIT_WORK_TREE to "no work tree"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 8, 2008, 12:05 UTC
Message-ID
<alpine.LSU.1.00.0802081203470.11591@racer.site>
In-Reply-To
<47AC02F5.9080705@viscovery.net>
Hi,
On Fri, 8 Feb 2008, Johannes Sixt wrote:
Show 32 quoted lines
> Johannes Schindelin schrieb:
> 
> > On Wed, 6 Feb 2008, Johannes Sixt wrote:
> > 
> >> Jeff King schrieb:
> >>> In setup_git_directory_gently, we have a special rule that says "if 
> >>> GIT_DIR is set but GIT_WORK_TREE is not, then use the current 
> >>> working directory as the work tree." This is the intended behavior 
> >>> for the user perspective.
> >>>
> >>> However, setup_git_directory_gently sets GIT_DIR itself, meaning 
> >>> that further setups (either because we are executing a command via 
> >>> alias, or in a subprocess) will see the non-existent GIT_WORK_TREE 
> >>> and assume we fall into the "current working directory is the 
> >>> working tree" codepath.
> >>>
> >>> Instead, we now use a special value of GIT_WORK_TREE to indicate 
> >>> that we have already checked for a worktree and that there isn't 
> >>> one, setting it when we set GIT_DIR and checking for it in the 
> >>> special case path.
> >>>
> >>> The special value is a blank GIT_WORK_TREE; it could be any value, 
> >>> but this should not conflict with any user values (and as a bonus, 
> >>> you can now tell git "I don't have a work tree" with "GIT_WORK_TREE= 
> >>> git", though I suspect the use case for that is limited).
> >>
> >> Hrm. Unfortunately, on Windows there is no such thing as an empty 
> >> environment string. setenv(x, "") *removes* the environment variable.
> > 
> > That might be a shortcoming of our implementation of setenv():
> 
> No, it is not. It's Windows's putenv(), and it's even documented.

Yes, that's what I said: our setenv() implementation uses putenv(), which introduces that bug (setenv() is not supposed to unset variables, unsetenv() is).

> That said, we probably should modify environ directly in gitsetenv().
Exactly.

Ciao, Dscho

Previous: Johannes Sixt
Message 13 of 13 in “allow setting GIT_WORK_TREE to "no work tree"”
  1. allow setting GIT_WORK_TREE to "no work tree"Jeff King, Feb 6, 2008
  2. Johannes SixtFeb 6, 2008
  3. Jeff KingFeb 6, 2008
  4. Junio C HamanoFeb 6, 2008
  5. Junio C HamanoFeb 6, 2008
  6. Jeff KingFeb 7, 2008
  7. Jay SoffianFeb 7, 2008
  8. Johannes SchindelinFeb 7, 2008
  9. Jay SoffianFeb 7, 2008
  10. Junio C HamanoFeb 7, 2008
  11. Johannes SchindelinFeb 7, 2008
  12. Johannes SixtFeb 8, 2008
  13. Johannes SchindelinFeb 8, 2008

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.