git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Emily Shaffer <emilyshaffer@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "Randall S. Becker" <rsbecker@nexbridge.com>,
	Git List <git@vger.kernel.org>
Subject: Re: Follow-up on hooks series
Date: Tue, 15 Mar 2022 13:25:05 -0700	[thread overview]
Message-ID: <CAJoAoZmBdgFez5Mrx9_GMaNtcTrTixEOjE+Gshs0umTbbXAOPw@mail.gmail.com> (raw)
In-Reply-To: <220315.86lexbdm4d.gmgdl@evledraar.gmail.com>

As threatened in IRC yesterday, adding Git list as well ;)

On Tue, Mar 15, 2022 at 12:57 PM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
>
> On Mon, Mar 14 2022, rsbecker@nexbridge.com wrote:
>
> > 1 I am not sure of the usefulness of the git hook list <hook> form. If you know the name of the hook, then you don’t need it listed. I get that it seems like a whereis style command. How
> >  about this:
> >  git hook list [ <hook-pattern> … ]
> >  that displays all hooks if none specified or those matching a pattern. The current message of hooks in hookdir is not particularly meaningful to me. hook bob found in .git/hooks explicitly
> >  would be more useful and better if you have patterns.
>
> That might be a good idea, I honestly haven't re-paged this into my brain.
>
> In any case this isn't in master/next or in-flight, there's just "git
> hook run" there, so let's discuss it when those patches are submitted
> (I'll CC you).


I'm a little unsure about what the semantics of this looks like, actually.

The way it works as implemented is like so:

$ git list pre-commit
# Because pre-commit can run more than one script, they all appear in
the output:
/usr/share/some-package/very-cool-pre-commit-hook
~/my-repo/hooks/project-specific-hook
~/src/script-i-wrote-to-watch-for-debug-printfs

That is, I know that I'm about to make a commit, but I don't remember
if I configured very-cool-pre-commit-hook and I need it for this
commit, so I want to list all my pre-commit hooks as a sanity check.

So I'm a little bit confused why it would be useful to grep with a
pattern. Are you expecting instead for something like:
$ git hook list '.*project-specific'
pre-commit: ~/my-repo/hooks/project-specific-hook
prepare-commit-msg: ~/my-repo/hooks/project-specific-check-commit-msg-hook

Or maybe even, given a config:
[hook "very-cool"]
  command = /usr/share/some-package/very-cool-pre-commit-hook
  event = pre-commit
[hook "very-cool-other-hook"]
  command = /usr/share/some-package/very-cool-pre-push-hook
  event = pre-push

to run something like
$ git hook list 'very-co*'
hook."very-cool".command=/usr/share/some-package/very-cool-pre-commit-hook
hook."very-cool".event=pre-commit
hook."very-cool-other-hook".command=/usr/share/some-package/very-cool-pre-push-hook
hook."very-cool-other-hook".event=pre-push

Both these examples I see a little less usefulness, but especially the
last one (which is essentially a thinly veiled 'git config
--get-regexp') doesn't seem useful to me. The "hook name" ("very-cool"
and "very-cool-other-hook" in this example) is pretty much an
implementation detail local to the config parse, and user will never
refer to it by that name after the config setup, right?

>
>
> > 2 I may have missed something, but I thought that this series might
> > allow execution of hooks if not in a repository – that was my hope
> > anyway. To do this, maybe add a --repository=<path> argument so that
> > git will know where to find the ./git/hooks directory, and then run
> > it.
>
> Yeah, some version of those patches does that, not sure which offhand...

Hrm. Well, I have a bit of a personal grudge against .git/hooks/ hooks
in general :) so I would say, if you will go through the pain of
wanting to reuse some hook in some specific repo all over your
machine, why not just set it up in your ~/.gitconfig instead, so you
don't have to pass this argument?

Better yet, if this argument is targeted for scripting, I think you
could achieve the same thing with 'git -c
core.hooksPath=~/myproject/.git/hooks/ hook run sendemail-validate',
and we wouldn't have to implement anything new at all.

 - Emily

       reply	other threads:[~2022-03-15 20:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <028301d837b1$173aacd0$45b00670$@nexbridge.com>
     [not found] ` <220315.86lexbdm4d.gmgdl@evledraar.gmail.com>
2022-03-15 20:25   ` Emily Shaffer [this message]
2022-03-15 22:37     ` Follow-up on hooks series rsbecker

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJoAoZmBdgFez5Mrx9_GMaNtcTrTixEOjE+Gshs0umTbbXAOPw@mail.gmail.com \
    --to=emilyshaffer@google.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=rsbecker@nexbridge.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).