无法从 Git post-receive hook 检测分支
我在远程存储库上设置了一个后接收挂钩,它尝试确定传入推送的分支名称,如下所示:
$branch = `git rev-parse --abbrev-ref HEAD`
不过,我发现的是,无论我从 $branch 变量推送哪个分支,都会被设置与‘主人’。
有什么想法吗?
I've got a post receive hook setup on the remote repo that tries to determine the branch name of the incoming push as follows:
$branch = `git rev-parse --abbrev-ref HEAD`
What i'm finding, though, is that no matter what branch I push from my $branch variable gets set with 'master'.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
post-receive 钩子获取与 pre-receive 相同的数据,但不是作为参数,而是从 stdin 获取。为所有引用发送以下内容:
oldRev (space) newRev (space) refName (Line feed)
您可以使用以下 bash 脚本解析出引用名称:
The post-receive hook gets the same data as the pre-receive and not as arguments, but from stdin. The following is sent for all refs:
oldRev (space) newRev (space) refName (Line feed)
You could parse out the ref name with this bash script:
您还可以使用 bash 变量替换执行类似的操作:
You could also do something like this using bash variable substitution:
马格努斯的解决方案对我不起作用,但 这个 做到了:
Magnus' solution didnt work for me, but this did:
这两个答案都是正确的,但我在将标准输入接收到电子邮件后的下一个常用功能时遇到问题。这是我最终得到的结果:
Both these answers are correct, but I was having trouble getting stdin to the next common function post-receive-email. Here is what I ended up with:
您需要读取传递给脚本的参数。那应该有分支名称和新旧修订,并为每个推送的分支运行
You need to read the arguments that are being passed to the script. That should have the branch name and new and old revisions and run for each branch pushed