From: "Gabriel Nützi" <gnuetzi@gmail.com>
To: Patrick Steinhardt <ps@pks.im>, Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>
Subject: Re: Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails
Date: Wed, 09 Oct 2024 13:53:17 +0200 [thread overview]
Message-ID: <5cd07a8d3c554815d4fce20996c018c6294c63e6.camel@gmail.com> (raw)
In-Reply-To: <ZwZPSA-J1RFQKYrw@pks.im>
[-- Attachment #1.1: Type: text/plain, Size: 5604 bytes --]
> 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...
Gabriel
-----Original Message-----
**From**: Patrick Steinhardt <[ps@pks.im](mailto:Patrick%20Steinhardt%20%3cps@pks.im%3e)>
**To**: Junio C Hamano <[gitster@pobox.com](mailto:Junio%20C%20Hamano%20%3cgitster@pobox.com%3e)>
**Cc**: Gabriel Nützi <[gnuetzi@gmail.com](mailto:Gabriel%20%3d%3fISO-8859-1%3fQ%3fN%3dFCtzi%3f%3d%20%3cgnuetzi@gmail.com%3e)>, [git@vger.kernel.org](mailto:git@vger.kernel.org), Karthik Nayak <[karthik.188@gmail.com](mailto:Karthik%20Nayak%20%3ckarthik.188@gmail.com%3e)>
**Subject**: Re: Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails
**Date**: 10/09/2024 11:39:26 AM
On Mon, Oct 07, 2024 at 02:02:02PM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <[ps@pks.im](mailto:ps@pks.im)> writes:
>
>
> > `$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.
>
>
> I've always considered "git rev-parse --git-dir" and friends were to
> verify the validity of the repository before returning "Your GIT_DIR
> is here". Otherwise there is no easy way to ask "I have this directory.
> Is it a valid repository you can work with?".
>
> So, I am not sure I agree with the above.
Well, I'm not sure either. I was merely pointing out that the documented
behaviour is different than the actual behaviour. Which of both is the
more sensible one is a different question.
> For what is worth, I am skeptical to the "solution" that tentively
> creates a bogus HEAD file while the repository is being initialized.
> The code today may ignore certain bogosity in such a HEAD (like the
> ".invalid" magic used during "git clone"), but there is no guarantee
> that a random third-party add-on a hook script may invoke do the
> same as we do, and more importantly, what a repository with its
> initialization complete look like may change over time and it may
> not be enough to have HEAD pointing at "refs/heads/.invalid" to fool
> our bootstrap process. If we were to go that route, I would rather
> see us pick a pointee that is *not* bogus at the mechanical level
> (i.e., "git symbolic-ref HEAD refs/heads/.invalid" would fail) but
> is clearly a placeholder value to humans, soon to be updated.
>
> Let's say if we were to create a repository with the name of initial
> branch as 'main', we could create HEAD that points at refs/heads/main
> bypassing any hook intervention, then call the hook to see if it
> approves the name. We'd need to make sure that we fail the
> repository creation when the hook declines, as it is refusing to set
> a HEAD, one critical element in the repository that has to exist,
> and probably remove the directory if we are not reinitializing.
>
> Or we could use a name that is clearly bogus to humans but is still
> structurally OK, say "refs/heads/hook-failed-during-initialization",
> ask the hook if it is OK to repoint HEAD to "refs/heads/main" from
> that state, and (1) if it approves, HEAD will point at "refs/heads/main"
> and "hook-failed-during-initialization" will be seen nowhere but the
> reflog of HEAD, or (2) if it refuses, we stop, and the user will be
> left on an unborn branch with a long descriptive name that explains
> the situation.
I dunno. It all feels rather complex.
> A much simpler alternative would be to simply ignore any hooks,
> traces, or anything that want to look into the directory we are
> working to turn into a repository but haven't completed doing so,
> during repository initialization, I would think, though.
That could work, yes, but it would limit the usefulness of the hook. In
theory, you can create a full log of all changes in the repository from
its inception. If we didn't log the first item, that log would be
incomplete.
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.
Patrick
[-- Attachment #1.2: Type: text/html, Size: 6229 bytes --]
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2024-10-09 11:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-20 10:07 Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails Gabriel Nützi
2024-09-20 10:42 ` Gabriel Nützi
2024-10-07 8:03 ` Patrick Steinhardt
2024-10-07 10:54 ` Gabriel Nützi
2024-10-07 10:57 ` Patrick Steinhardt
2024-10-07 11:02 ` Gabriel Nützi
2024-10-07 11:24 ` Patrick Steinhardt
2024-10-07 21:02 ` Junio C Hamano
2024-10-09 9:39 ` Patrick Steinhardt
2024-10-09 10:09 ` Karthik Nayak
2024-10-09 11:53 ` Gabriel Nützi [this message]
2024-10-09 12:19 ` Patrick Steinhardt
[not found] ` <B0631C6D-0914-4C25-AAF7-E742129836FC@gmail.com>
2024-10-14 12:25 ` Patrick Steinhardt
2024-10-09 17:31 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5cd07a8d3c554815d4fce20996c018c6294c63e6.camel@gmail.com \
--to=gnuetzi@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).