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

Re: `git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE

From
Jeff King <peff@peff.net>
Date
Mar 29, 2016, 19:41 UTC
Message-ID
<20160329194156.GA9527@sigill.intra.peff.net>
In-Reply-To
<xmqqshz9z5hu.fsf@gitster.mtv.corp.google.com>
On Tue, Mar 29, 2016 at 08:08:29AM -0700, Junio C Hamano wrote:
> So it is a misconfiguration if you only set GIT_WORK_TREE without
> setting GIT_DIR.

Hmm. I have frequently done this when my cwd is a git repository (e.g., a bare one), and it works as you'd expect (find the git-dir in the current path, then the working tree via $GIT_WORK_TREE).

I always assumed that was the intended behavior, as it is the only one that makes sense. I suspect I am not alone in having relied on this.

Show 18 quoted lines
> Also, if you set both and run Git from outside $GIT_WORK_TREE, even
> though Git may try to do its best to give you a reasonable behaviour
> [*1*], it is working by accident not by design (see the statement
> you are making by setting GIT_WORK_TREE in the third bullet above).
> 
> IOW, running from outside GIT_WORK_TREE is a misconfiguration.
> 
> [Footnote]
> 
> *1* Think what should happen when you are outside GIT_WORK_TREE and
>     say this:
> 
> 	$ git grep foo
> 
>     As you are not even inside the working tree, the command would
>     not know in which subdirectory you want to find the string foo;
>     the "reasonable behaviour" is to work on the whole working tree
>     in this case.

Likewise, I always assumed this "reasonable behavior" was intended. When we setup_git_directory(), we end up in the root of the working tree as usual. The "prefix" must be empty, as we were not in the work tree at all, and we do a whole-tree operation.

Those behaviors may not have been fully designed, but as they do the only reasonable thing (besides dying with an error), and people may have baked that assumption into their scripts, I think we should avoid changing them unless there is a compelling reason.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 16 in “`git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE”
  1. Elliott CableMar 29, 2016
  2. Elliott CableMar 29, 2016
  3. John KeepingMar 29, 2016
  4. Junio C HamanoMar 29, 2016
  5. Jeff KingMar 29, 2016
  6. Junio C HamanoMar 29, 2016
  7. Jeff KingMar 29, 2016
  8. Jeff KingMar 29, 2016
  9. John KeepingMar 29, 2016
  10. Jeff KingMar 29, 2016
  11. John KeepingMar 29, 2016
  12. John KeepingMar 29, 2016
  13. Jeff KingMar 29, 2016
  14. Junio C HamanoMar 29, 2016
  15. Duy NguyenMar 30, 2016
  16. Elliott CableApr 1, 2016

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.