Re: [PATCH 0/4] pre-push hook support

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 0/4] pre-push hook support

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:36

Aaron Schrab [off-list ref] writes:
There have been at least a couple of submissions to add support for a
pre-push hook, which were rejected at least partially because they didn't
provide enough information to a hook script for it to determine what was
to be pushed any better than a separate wrapper around the 'git push'
command would be able to do.  In this series I attempt to address that
problem.

The first two patches in this series do a little bit of refactoring in
order to make it easier to call hooks with a variable number of arguments.

The third patch actually adds support for calling a pre-push hook.  If it
exists, it will be called with the name and URL of the destination remote
(if a named remote isn't being used, the URL will be supplied for both)
followed by another argument for each ref being pushed; these arguments
take the form:

  <local ref>:<local sha1>:<remote ref>:<remote sha1>
One lesson we learned long time ago while doing hooks is to avoid
unbound number of command line arguments and instead feed them from
the standard input.  I think this should do the same.
This should provide enough information for a script to easily determine
the set of commits that is being pushed, and thus make a decision if that
should be allowed.
How does the hook communicate its decision to the calling Git?

Will it be "all-or-none", or "I'll allow these but not those"?

Re: [PATCH 0/4] pre-push hook support

From: Aaron Schrab <hidden>
Date: 2016-06-15 22:55:37

At 18:01 -0800 28 Dec 2012, Junio C Hamano [off-list ref] wrote:
One lesson we learned long time ago while doing hooks is to avoid
unbound number of command line arguments and instead feed them from
the standard input.  I think this should do the same.
Good point.  I had been trying to keep the interface for this hook as 
close as possible to the ones for other client-side hooks on the theory 
that less development effort may go into those than for server-side 
hooks.  But thinking on that more I certainly see that this could easily 
run into limits on argument length on some systems; especially when it's 
likely that each of those arguments is likely to be over 100 bytes long.

I'll work on an updated version which sends the variable length 
information over a pipe, using the command-line arguments only to pass 
the remote name and URL.
How does the hook communicate its decision to the calling Git?

Will it be "all-or-none", or "I'll allow these but not those"?
Currently it just uses the exit code to communicate that back, so it's 
all-or-none.  I think I'll keep that in the updated version as well.

A future enhancement could modify the protocol to support reading from 
the hook's stdout the names of remote refs which are to be rejected, I 
think that just having the option for all-or-nothing is a good starting 
point.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help