我如何对 git hooks 中的新标签做出反应?

发布于 2024-11-03 20:39:51 字数 261 浏览 4 评论 0原文

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

我很确定我想将其附加到接收后,但是我在有关 git hooks 的文档中找不到有关如何读取传入标签的任何内容。它们是通过不同的钩子交付的吗?我实际上是否需要让 shell 脚本运行 git 命令来查看新提交是否有新标签?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-11-10 20:39:51

标签和其他任何东西一样都是引用(比如提交)。
如果使用 post-receive 挂钩 将标签推送到存储库,则该挂钩将被调用并列出所有更新的引用,即所有引用的旧值和新值以及它们的名称(在其标准输入上)。

请参阅此服务器接收电子邮件后挂钩例如。

#!/bin/bash

. $(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

为此,您还必须安装函数文件上述示例挂钩存储库。

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/bash

. $(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文