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

how to access working tree from .git dir?

From
JEJosh England <jjengla@sandia.gov>
Date
Sep 6, 2007, 23:20 UTC
Message-ID
<1189120800.6203.23.camel@beauty>

In messsing around with hooks, I've discovered that not all hooks are run in the same environment. In particular, the current working directory in the post-receive hook (maybe others as well) is the GIT_DIR (.git) directory, instead of the root of the working tree (as in pre-commit).

This wouldn't be so bad, but it seems that `git rev-parse --show-cdup` does not show anything valid if your current working directory is inside the .git dir. This creates a scenario where there is no consistent way to access the root of the working tree from within a hook. To make things worse, the behavior changes subtly whether $GIT_DIR is defined or not.

I've got a patch that changes the current working directory before calling the post-receive hook, but that's more of a workaround than a fix. I'd like to be able to run `git rev-parse --show-cdup` from with a .git directory and have it produce a valid result.

So:  I'm poking around around and trying to find the right answer but
some things look weird.  If anyone knows the quick-and-easy answer here
please let me know.  Otherwise, I'll continue to poke around some more.
Thanks,
-JE
Next: Junio C Hamano
Message 1 of 9 in “how to access working tree from .git dir?”
  1. Josh EnglandSep 6, 2007
  2. Junio C HamanoSep 7, 2007
  3. Josh EnglandSep 7, 2007
  4. Junio C HamanoSep 7, 2007
  5. Josh EnglandSep 7, 2007
  6. Junio C HamanoSep 7, 2007
  7. Josh EnglandSep 7, 2007
  8. Junio C HamanoSep 7, 2007
  9. Josh EnglandSep 8, 2007

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.