Re: Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 7, 2024, 11:24 UTC
- Message-ID
- <ZwPEwL-fKHBkUOcm@pks.im>
- In-Reply-To
- <a8807b44026458097267932f429ef61d5b77aa4c.camel@gmail.com>
On Mon, Oct 07, 2024 at 01:02:56PM +0200, Gabriel Nützi wrote:
> Ah, jeah thats true: > > The command in question which is `git rev-parse --git-dir` to find the actual GIT_DIR is actually the issue here: > It relies on having a proper HEAD despite the docs saying it only reports GIT_DIR if set etc...
That's not quite true. The second paragraph for the `--git-dir` option in git-rev-parse(1) has this to say:
If $GIT_DIR is not defined and the current directory is not detected to lie in a Git
repository or work tree print a message to stderr and exit with nonzero status.But in our case you're correct: `$GIT_DIR` _is_ defined during hook execution. So in theory, if git-rev-parse(1) behaved exactly as documented, it shouldn't even care whether or not it is executing in a repository.
> Could we maybe make these commands more agnostic?
So this could indeed be a viable fix, but I guess we'd rather play whack-a-mole because other Git commands that one may want to execute in this repository would also be broken.
> Making an empty HEAD probably directly also resolves these commands to work correctly.
So agreed, creating a stub HEAD is the most sensible option we have. I'd like to wait a bit for more feedback from other contributors before we do so though.
Patrick