我如何对git钩子中的新标签做出反应? [英] How do I react to new tags in git hooks?

查看:147
本文介绍了我如何对git钩子中的新标签做出反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个git钩子,它根据传入标签创建一个CDN风格的目录结构。因此,例如,如果本地存储库中的最后一个标签是v1.2.1,并且我使用v1.2.2提交了一个提交,它应该会看到新标签并直接将存储库克隆到新的存储库中(../1.2 .2)相应地。

我很确定我想把它附加到post-receive上,但是在关于git钩子的文档中我找不到任何关于如何读取传入的标签。它们是在不同的钩子上交付的?我真的需要让shell脚本运行一个git命令来查看是否有任何新的提交有新标签吗?

谢谢!


标签与任何其他标签一样(如提交)。

如果标签被推送到一个带有 post-receive hook ,该钩子将被调用,并将列出所有更新的参考,既旧又新除了它们的名字(在它的标准输入上)之外,所有ref的值。

看到这个服务器 post-receive email

 #!/ bin / sh 

。 $($ dirname $ 0)/ functions
$ b $ process_ref(){
oldrev = $(git rev-parse $ 1)
newrev = $(git rev-parse $ 2)
refname =$ 3

set_change_type
set_rev_types
set_describe_tags

案例$ refname,$ rev_typein
refs /标记/ *,标记)
#带注释的标记
refname_type =带注释的标记
function =atag
short_refname = $ {refname ## refs / tags /}
#更改收件人
如果[-n$ announcerecipients];那么
recipients =$ announcerecipients
fi
;;
esac
}

读REF;做process_ref $ REF;完成

为此,您还必须安装函数文件


I'd like to set up a git hook that creates a CDN-style directory structure based on incoming tags. So, for example, if the last tag in the local repository is "v1.2.1" and I pull a commit with "v1.2.2", it should see the new tag and clone the repository into a new directly (../1.2.2) accordingly.

I'm pretty sure I want to attach this to post-receive, however I can't find anything in the documentation about git hooks about how to read the incoming tags. Are they delivered on a different hook? Do I actually need to have the shell script run a git command to see if any of the new commits have new tags?

Thanks!

解决方案

Tags are refs like any other (like commit).
If tags are pushed to a repo with a post-receive hook, that hook will be called and will list all updated refs, that is both old and new values of all the refs in addition to their names (on its standard input).

See this server post-receive email hook for example.

#!/bin/sh

. $(dirname $0)/functions

process_ref() {
    oldrev=$(git rev-parse $1)
    newrev=$(git rev-parse $2)
    refname="$3"

    set_change_type
    set_rev_types
    set_describe_tags

    case "$refname","$rev_type" in
      refs/tags/*,tag)
        # annotated tag
        refname_type="annotated tag"
        function="atag"
        short_refname=${refname##refs/tags/}
        # change recipients
        if [ -n "$announcerecipients" ]; then
          recipients="$announcerecipients"
        fi
      ;;
    esac 
}

while read REF; do process_ref $REF; done

For this to work you also must install the functions file from the aforementioned example hook repository.

这篇关于我如何对git钩子中的新标签做出反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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