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
Junio C Hamano <gitster@pobox.com>
Date
Mar 29, 2016, 22:35 UTC
Message-ID
<xmqq1t6sx685.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160329221657.GA31811@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 9 quoted lines
>   $ echo content >../file
>   $ GIT_WORK_TREE=$(cd ..; pwd) GIT_DIR=$(pwd) git add file
>   fatal: pathspec 'file' did not match any files
>
> I'd expect that to work, and it doesn't, because we pass ".git/" as the
> "prefix" to cmd_add(). Which I guess is true, but it feels kind of weird
> (I think most people who set both variables like that would generally
> point to some other directory entirely, and we would have a NULL
> prefix).

That reminds me of a related tangent. If we really want to properly support running from outside the working tree (or from inside .git for that matter), I suspect we need two separate "prefix" for two different uses. The "we would have a NULL prefix" is what was considered the true "prefix" traditionally, i.e. it is the directory to which any pathspecs and relative paths that name paths in the history are taken relative to. E.g. if you run "git add HEAD" from inside your GIT_DIR but you have GIT_WORK_TREE set up correctly, you would want to add HEAD from the root of the working tree.

Another is the base directory for a relative filename that names a file that does not have anything to do with the paths in the history. E.g. if you run "git grep --file patterns" from outside the working tree but with GIT_DIR/GIT_WORK_TREE correctly set up, you would still want to read the "patterns" file from the current directory.

The former can be done by using prefix=NULL to say "we may or may not have come from outside a working tree but we no longer care after we chdir(2) to the root of the working tree. Any path is relative to the root of the working tree." But then we may lose the clue to read from the latter (the OPT_FILENAME option is handled by prefix_filename() using the prefix).

The distinction between the two does not exist as long as you start inside GIT_WORK_TREE and outside GIT_DIR.

Previous: Jeff KingNext: Duy Nguyen
Message 14 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.