简体   繁体   English

将参数传递给git pre-push hook

[英]Pass parameters to git pre-push hook

I've create a git pre-push hook that builds my .NET solution and runs the unit tests. 我已经创建了一个git pre-push hook来构建我的.NET解决方案并运行单元测试。 So executing a git push command now fires off the build/tests prior to pushing code to origin. 因此,执行git push命令现在会在将代码推送到源之前触发构建/测试。

That all works just fine. 一切正常。 However, there are cases when I'd like to bypass this hook. 但是,有些情况下我想绕过这个钩子。 Maybe I know a test is failing and that's fine for now, I'd just like to be able to skip the logic in my hook. 也许我知道测试失败了,现在没关系,我只想跳过我的钩子中的逻辑。

Ideally I'd be able to do something like this: 理想情况下,我可以做这样的事情:

git push --skip-tests

However, that doesn't seem to fly because git flags --skip-tests as an invalid parameter. 但是,这似乎没有飞,因为git标志--skip-tests作为无效参数。 Is there a way I can pass a parameter into the hook from the command line when doing a push so that I can branch the hook logic based on whether that parameter exists or not? 有没有一种方法可以在执行推送时从命令行将参数传递到钩子中,以便我可以根据该参数是否存在来分支钩子逻辑?

You should skip it with: 你应该跳过它:

git push --no-verify

From git push man page git push手册页

With --no-verify , the hook is bypassed completely. 使用--no-verify ,挂钩完全被绕过。


However, this bypass not just the tests but the all hook: build too. 然而,这不仅仅是测试,而是所有钩子:也是构建。

You could keep the hook, but add an environment variable that the hook script would detect in order to build but not test. 您可以保留挂钩,但添加一个环境变量,钩子脚本将检测该环境变量以便构建但不进行测试。

skip-test=true git push

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

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