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

Re: Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 9, 2024, 12:19 UTC
Message-ID
<ZwZ01-mtwm9Gcjub@pks.im>
In-Reply-To
<5cd07a8d3c554815d4fce20996c018c6294c63e6.camel@gmail.com>
On Wed, Oct 09, 2024 at 01:53:17PM +0200, Gabriel Nützi wrote:
Show 13 quoted lines
> 
> > We have another solution that is even simpler: just do nothing. I do not  
> > think that the behaviour we exhibit is wrong. Unwieldy? Maybe. But it is  
> > merely stating facts: we are executing a transaction in a repository  
> > that is not yet fully set up. If you don't want that, either don't set  
> > up a global reference-transaction hook, or alternatively handle that  
> > edge case in your script.
> 
> But then Git should at least give the hooks maintainers a chance to know what it is doing.
> Could we have a new env. variable or mechanism stating that the repository is not yet setup or so?
> The issue here comes from the fact that Githooks is a hooks manager which basically calls `reference-transaction` for you, but before
> it does it calls `git rev-parse --git-dir` to get the correct Git directory, basically not doing env. lookup on GIT_DIR which this command actually does, but that apparently only works on a "initialized" repo, so currently I do a workaround and looking directly at GIT_DIR.
> I would be really happy also if I could somehow know when Git is creating a new repository (clone, or init), that would also improve other scenarios I came across. Basically you cannot react on hook `post-checkout` only when a new repo is created...
Yeah, that's fair indeed, thanks for the background.

In practice you already have a unique way to identify whether the repo is about to be created or whether you're using "normal" operations, namely by checking whether the HEAD file exists in the Git directory. Is that an acceptable workaround for you?

As said, we're currently just exploring options. I'm not yet saying that this is the way we'll go, even though it seems like the most sensible solution to me right now. That picture of course changes when there are valid usecases like what you present here.

Patrick
Previous: Gabriel NütziNext: Junio C Hamano
Message 12 of 14 in “Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails”
  1. Gabriel NütziSep 20, 2024
  2. Gabriel NütziSep 20, 2024
  3. Patrick SteinhardtOct 7, 2024
  4. Gabriel NütziOct 7, 2024
  5. Patrick SteinhardtOct 7, 2024
  6. Gabriel NütziOct 7, 2024
  7. Patrick SteinhardtOct 7, 2024
  8. Junio C HamanoOct 7, 2024
  9. Patrick SteinhardtOct 9, 2024
  10. Karthik NayakOct 9, 2024
  11. Gabriel NütziOct 9, 2024
  12. Patrick SteinhardtOct 9, 2024
  13. Junio C HamanoOct 9, 2024
  14. Patrick SteinhardtOct 14, 2024

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.