0
votes

I have created a custom git pre-receive hook as per steps mentioned here

https://docs.gitlab.com/ee/administration/custom_hooks.html

Its a shell script which does some analysis of the commits and rejects them if there are any issues. However it can have lot of positives and developers should not find it a nuisance. So is there a way that they can force push even if the pre-receive hook fails ? I tried

git push --force 

but it is still rejected.

1

1 Answers

0
votes

The push server side hooks are not supposed to be overridable by remote users, they are often used to force various policies. So no, --force or any option do not override them.

You can, however, make the script pass the push, if remote user asks for it somehow. It can be decided based on the target branch, commit message or some other information. There is also a straightforward way to specify an option at the push command-line

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.