简体   繁体   English

强制推送git pre-receive hook错误

[英]force push a git pre-receive hook error

I have created a custom git pre-receive hook as per steps mentioned here 我已经按照此处提到的步骤创建了一个自定义git pre-receive钩子

https://docs.gitlab.com/ee/administration/custom_hooks.html 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. 它是一个shell脚本,它对提交进行一些分析,如果有任何问题,则拒绝它们。 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. 但它仍然被拒绝。

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. 因此, --force或任何选项都不会覆盖它们。

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 还有一种直接的方法可以在push命令行中指定选项

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. 可以从环境变量GIT_PUSH_OPTION_COUNT读取git push --push-option = ...命令行上给出的push选项的数量,这些选项本身可以在GIT_PUSH_OPTION_0,GIT_PUSH_OPTION_1等中找到。使用push选项阶段时,将不会设置环境变量。 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. 如果客户端选择使用推送选项,但不发送任何推送选项,则计数变量将设置为零,即GIT_PUSH_OPTION_COUNT = 0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM