git post hook内的分支名称 [英] Branch name within git post hook

查看:194
本文介绍了git post hook内的分支名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用这个方法来访问git serverside钩子中的回购商品的名称。有没有一种方法可以访问分支名称?

其意图是,只要有人推到这个裸回购,一个钩子会触发它调用另一个脚本并通过它

解决方案

由于repo的名称(已经这样做了)以及刚刚推送的分支的分支名称。在 git post-receive hook如何获取它正在运行的repo的名称?中提到,一个post-receive钩子可以接收来自多个分支的提交:

 #!/ bin / bash 
while readre oldrev newrev refname

branch = $(git rev-parse --symbolic --abbrev-ref $ refname)
if [master==$ branch];然后
#调用您的脚本
fi
完成

您的脚本可能最终被称为多次次。


So I used this method to access the name of a repo within a git serverside hook. Is there a way to access the branch name as well?

The intention is that whenever someone pushes to this bare repo, a hook will trigger that calls another script and passes it the name of the repo (already does this) as well as the branch name of the branch that was just pushed.

解决方案

As mentioned in "how can git post-receive hook get name of repo it is running on?", a post-receive hook can receive commits from multiple branches:

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" == "$branch" ]; then
        # Call your script
    fi
done

Your script could end up being called multiple times.

这篇关于git post hook内的分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆