From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Aske Olsson <askeolsson@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] Add support for a 'pre-push' hook
Date: Sat, 17 Nov 2012 07:39:28 +0100 [thread overview]
Message-ID: <50A73120.9040301@alum.mit.edu> (raw)
In-Reply-To: <7vvcd5l290.fsf@alter.siamese.dyndns.org>
On 11/16/2012 09:30 PM, Junio C Hamano wrote:
> Aske Olsson <askeolsson@gmail.com> writes:
>
>> If the script .git/hooks/pre-push exists and is executable it will be
>> called before a `git push` command, and when the script exits with a
>> non-zero status the push will be aborted.
>> The hook can be overridden by passing the '--no-verify' option to
>> `git push`.
>>
>> The pre-push hook is usefull to run tests etc. before push. Or to make
>> sure that if a binary solution like git-media, git-annex or git-bin is
>> used the binaries are uploaded before the push, so when others do a
>> fetch the binaries will be available already. This also reduces the
>> need for introducing extra (git) commands to e.g. sync binaries.
>>
>> Signed-off-by: Aske Olsson <askeolsson@gmail.com>
>> ---
>> ...
>> +[[pre-push]]
>> +pre-push
>> +~~~~~~~~
>> +
>> +This hook is invoked by 'git push' and can be bypassed with the
>> +`--no-verify` option. It takes no parameter, and is invoked before
>> +the push happens.
>> +Exiting with a non-zero status from this script causes 'git push'
>> +to abort.
>> ...
>> + if (!no_verify && run_hook(NULL, "pre-push")) {
>> + die(_("pre-push hook failed: exiting\n"));
>> + }
>
> NAK, at least in the current form. At least the system should tell
> the hook where it is pushing and what is being pushed.
I agree.
> Besides, there are five valid reasons to add a new hook to the
> system, but your version of pre-push does not satisfy any of them:
>
> http://thread.gmane.org/gmane.comp.version-control.git/94111/focus=71069
Here I disagree. I think it satisfies (1):
> (1) A hook that countermands the normal decision made by the
> underlying command. Examples of this class are the update
> hook and the pre-commit hook.
pre-push would be very similar in spirit to pre-commit: pre-commit is a
filter that can prevent a "bad" commit from getting into the local
repository; pre-push is similarly a filter between the local repo and
remote repositories.
I also think it satisfies (2) and/or (5b):
> (2) A hook that operates on data generated after the command
> starts to run. [...]
> (5) [...] Another example is the post-checkout
> hook that gets information that is otherwise harder to get
> (namely, if it was a branch checkout or file checkout --
> you can figure it out by examining the command line but
> that already is part of the processing git-checkout does
> anyway, so no need to force duplicating that code in the
> userland).
It would not be trivial for a wrapper script to figure out what branches
and commits are about to be pushed. But "git push" could tell the hook
script what branches are to be pushed. And if the pre-push hook is run
after negotiation between client and server of what commits need to be
transfered, the hook could also be provided that information and use it
to figure out which commits it should vet.
Although a pre-receive script on the remote repository could do most of
the same things as a pre-push script, the latter would sometimes have
advantages because it is run "client-side":
* When the user doesn't have the ability to change the pre-receive
script on the server (think public git hosting services).
* For user-specific actions that are not wanted by all users pushing to
the same server (for example, maybe I add the string "WIP" to commit
messages for commits that are not ready to be pushed; my pre-push script
could verify that I don't push such a commit by accident).
* Preventing "secret" info (password files, proprietary branches) from
being pushed. Even if the remote repo were taught to reject them, they
would have already traversed the internet.
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
next prev parent reply other threads:[~2012-11-17 6:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-16 19:42 [PATCH] Add support for a 'pre-push' hook Aske Olsson
2012-11-16 20:25 ` Matthieu Moy
2012-11-16 21:23 ` Junio C Hamano
2012-11-17 9:00 ` Aske Olsson
2012-11-16 20:30 ` Junio C Hamano
2012-11-17 6:39 ` Michael Haggerty [this message]
2012-11-17 8:47 ` Aske Olsson
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=50A73120.9040301@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=askeolsson@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox