Question

Is there a way how to explicitly bypass firing the post-receive hook? Meaning after pushing commit the post-receive hook won't run.

Était-ce utile?

La solution

It doesn't seem to be possible with git alone on the receiving (server -side) end: you need to customize your hook in order to allow that case (skip) to occur.
This differ from local hooks, that you can skip (for some of them).

See for example hooks in "Skip processing of Git revisions in post-receive hook that have already been previously processed" (which is about partialy skipping some commits, but the idea is similar)

Autres conseils

It is quite possible to skip post-receive hook with use of push-options.

To make is happen you need three ingredients:

1)

According to man githooks, post-receive section:

The number of push options given on the command line of git push --push-option=... can be read from the environment variable GIT_PUSH_OPTION_COUNT, and the options themselves are found in GIT_PUSH_OPTION_0, GIT_PUSH_OPTION_1,... If it is negotiated to not use the push options phase, the environment variables will not be set. If the client selects to use push options, but doesn’t transmit any, the count variable will be set to zero, GIT_PUSH_OPTION_COUNT=0.

So you can prepare your post-receive hook script like this:

if [ "x${GIT_PUSH_OPTION_COUNT}" = "x0" ] ; then
    exec /usr/share/buildbot/contrib/git_buildbot.py --master=172.16.1.1:8989 --auth="***" --category=yaal --project=yaal --repository=yaal "${@}"
fi

2)

According to git-config-receiveadvertisePushOptions:

When set to true, git-receive-pack will advertise the push options capability to its clients. False by default.

So you need to add this configuration on your remote like so:

git config receive.advertisePushOptions true

Or edit your project.git/config manually.

3)

For pushes that you do not want for your post-receive hook to fire simply add dummy push option, like so:

git push -o blah

Using $GIT_PUSH_OPTION_(n) you can make your pushes even more sophisticated.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top