git hooks 及其工作原理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1717278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git hooks and how they work
提问by brad
So I'm trying to get hudson to build with a post-receive hook. In my local git repo I set post-receive.sample to just post-receive, chmod 755 and added in the line:
所以我试图让 hudson 使用 post-receive hook 来构建。在我的本地 git repo 中,我将 post-receive.sample 设置为 post-receive, chmod 755 并添加到行中:
/usr/bin/curl -u user:secret http://localhost:8080/hudson/job/MyJob/build?token=secondsecret
If I force a build, hudson updates the code, but here's what I don't understand, the hooks in that repo DON't have the .sample after them like they do locally, and the post-receive in the hudson repo doesn't have that line of code above. What's going on here and how are hooks integrated into the whole git process? Do I need to be changing this hook on the remote repo? I would have thought it was enough to do it locally and push so anyone fetching from that repo get the new hooks. I can't understand how another user's repo would have different hooks.
如果我强制构建,hudson 会更新代码,但这是我不明白的,那个 repo 中的钩子不像他们在本地那样在它们之后有 .sample,并且 hudson repo 中的 post-receive 没有'没有上面那行代码。这里发生了什么,钩子是如何集成到整个 git 过程中的?我需要在远程仓库上更改这个钩子吗?我原以为在本地完成并推送就足够了,这样任何从该 repo 中获取的人都可以获得新的钩子。我无法理解另一个用户的 repo 会有不同的钩子。
回答by ndim
You basically have two options:
你基本上有两个选择:
- Place the
post-receive
hook on the serverand let the server run curl. - Place a
post-commit
hook on your local repo and let your local box run curl.
- 将
post-receive
钩子放在服务器上,让服务器运行 curl。 post-commit
在您的本地存储库上放置一个钩子,让您的本地框运行 curl。
As your build job will probably fetch the code to build from the repo on the server, only option 1. makes sense. In case 2., the build job would probably have to fetch the code from your local box, and that is probably not what you want.
由于您的构建作业可能会从服务器上的存储库中获取要构建的代码,因此只有选项 1. 有意义。在第 2 种情况下,构建作业可能必须从您的本地框中获取代码,这可能不是您想要的。
You cannot place hooks onto the serverusing git push
. You (or someone with the appropriate permissions) needs to do that by manually logging into serverand modifying the hook script files locally.
你不能把钩到服务器使用git push
。您(或具有适当权限的人)需要通过手动登录服务器并在本地修改钩子脚本文件来做到这一点。
回答by Stefan N?we
Hooks are not shared through the repository. You need to install the hook at the remote side.
钩子不通过存储库共享。您需要在远程端安装钩子。