From: Anders Waldenborg <anders@0x63•nu>
To: git@vger•kernel.org
Cc: Alexander Potashev <aspotashev@gmail•com>,
Marc Weber <marco-oweber@gmx•de>,
git@vger•kernel.org, Rogan Dawes <lists@dawes•za.net>,
martin f krafft <madduck@madduck•net>
Subject: Re: What about allowing multiple hooks?
Date: Wed, 21 Jan 2009 21:35:58 +0100 [thread overview]
Message-ID: <4977872E.70901@0x63.nu> (raw)
In-Reply-To: <7vd4f3z8xu.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
> I deliberately omitted support for multiple scripts in core git Porcelains
> to avoid this exact issue. It is a huge can of worms and it is dubious if
> you can have a coherent and generic enough semantics.
>
> In the meantime, you can have a single .git/hooks/pre-commit script that
> defines your own convention. Maybe it uses .git/hooks/pre-commit.d/
> directory, full of scripts, and implements the semantics you want,
> including:
>
> (1) the execution order and the naming convention of the scripts (e.g.
> they all live in pre-commit.d/ directory, and executed in ASCII byte
> value order of their names);
>
> (2) how their exit status combine together.
I need multiple hooks, so I've done some thinking about this, so I
thought it may be a good idea to share this here.
I currently use configvalues to specify which hooks to run. For example
this is how my post-receive looks:
data=$(cat)
git config --get-all hooks.post-receive.hook | while read hook; do
$hook <<__EOF__
"$data"
__EOF__
done
Now none of my hooks wants to prevent update, so I don't care about
return status. But it could easily be extended, for example by having
some indicator per hook that can have the values (are these enough?):
ignore - pretent that no failure was returned no matter what
sufficient - if this hook suceeds end result is always sucess
required - if this hook fails we fail, no more hooks are run
That could be done with the simple configvalue thing as follows:
git config -add hooks.post-receive.hook \
"sufficient allow-repo-owner-to-do-anything.sh"
git config -add hooks.post-receive.hook \
"required finegrained-access-control.sh"
git config -add hooks.post-receive.hook \
"required allow-repo-owner-to-do-anything.sh"
git config -add hooks.post-receive.hook \
"ignore send-mail.sh"
git config -add hooks.post-receive.hook \
"ignore send-irc-notification.py"
One problem is that to change order one has to resort to manually
editing config. So maybe something richer could be used:
[hooks "allow-repo-owner-to-do-anything"]
cmd = /usr/share/git-hooks/allow-repo-owner-to-do-anything.sh
enabled = 1
type = post-receive
mode = sufficient
priority = 10
[hooks "mail"]
cmd = /usr/share/git-hooks/allow-repo-owner-to-do-anything.sh
enabled = 1
type = post-receive
mode = ignore
priority = 1000
(this would even allow running hooks at same priority simultaneously)
Also then the hook's own config variables fits nicely in same section.
(note that then each [hooks "x"] will be an instance that could use the
same script, but different configvars)
anders
next prev parent reply other threads:[~2009-01-21 20:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-21 13:38 What about allowing multiple hooks? Marc Weber
2008-11-21 13:55 ` martin f krafft
2008-11-21 14:56 ` Rogan Dawes
2009-01-03 23:32 ` Alexander Potashev
2009-01-04 10:01 ` Junio C Hamano
2009-01-21 20:35 ` Anders Waldenborg [this message]
2009-01-21 21:10 ` Johannes Schindelin
2009-01-21 21:30 ` Anders Waldenborg
2009-01-21 21:50 ` Johannes Schindelin
2009-01-22 9:57 ` Anders Waldenborg
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=4977872E.70901@0x63.nu \
--to=anders@0x63$(echo .)nu \
--cc=aspotashev@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=lists@dawes$(echo .)za.net \
--cc=madduck@madduck$(echo .)net \
--cc=marco-oweber@gmx$(echo .)de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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