git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add support for a 'pre-push' hook

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 16, 2012, 20:30 UTC
Message-ID
<7vvcd5l290.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAJwKrPYwCE4ExmK09PURMfjYezn6vdCH_BBXU4WCwrnotyV9CA@mail.gmail.com>
Aske Olsson <askeolsson@gmail.com> writes:
Show 28 quoted lines
> 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.

After working on my notebook, I may want to push to my desktop machine first to test it, without having to test locally on an underpowered CPU, but when I am publishing the end result to the wider world, I do want to test the result beforehand. Without "where am I pushing", the hook would not help me to enforce testing only for the latter.

A lazy "git push" without any other argument may be configured in my repository to push its "maint", "master", "next" and "pu" branches to the public repository. I may say "git push origin +pu", while on one of the topic branches, to push only the "pu" branches out before I am confident that the other branches I'll eventually publish are ready (it is more likely that I may even *know* they are broken and do not pass the test in such a case, and that is why I am pushing only "pu" out). I'd want to run tests only on 'pu' in such a case. Without "what am I pushing", the hook would not be able to help me doing that, either.

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

It is more like "to always cause an action before running a git operation locally," so you can even write

    cat >$HOME/bin/git-mypush <<\EOF
    #!/bin/sh
    run test || exit
    exec git push "$@"
    EOF
    chmod +x $HOME/bin/git-mypush
and then can run "git mypush" instead of adding this hook.
Previous: Aske OlssonNext: Michael Haggerty
Message 5 of 7 in “Add support for a 'pre-push' hook”
  1. Add support for a 'pre-push' hookAske Olsson, Nov 16, 2012
  2. Matthieu MoyNov 16, 2012
  3. Junio C HamanoNov 16, 2012
  4. Aske OlssonNov 17, 2012
  5. Junio C HamanoNov 16, 2012
  6. Michael HaggertyNov 17, 2012
  7. Aske OlssonNov 17, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.