禁用标记删除 [英] Disable tag deletion

查看:102
本文介绍了禁用标记删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个中央仓库,一个团队发布(推送)他们的提交。
在这个主存储库中,我想禁用标记删除和重命名。



是否有像钩子之类的解决方案?

解决方案

git help hooks 包含有关钩子的文档。当Git即将创建/移动/删除引用时,会调用 update 钩子。它被调用一次,每个引用被更新,并给出:


  • 第一个参数:引用名称(例如,refs / tags / v1
  • 第二个参数:引用当前指向的对象的SHA1(如果引用当前不存在,全为零)

  • 第三个参数:用户希望引用指向的对象的SHA1(如果引用将被删除,全部为0)。


    如果使用非零退出代码退出钩子, git 不会更新引用,并且用户将收到错误消息。



    因此,为解决您的特定问题,您可以将以下内容添加到 update 挂钩中:

     #!/ bin / sh 

    log(){printf'%s\\\
    '$ *; }
    error(){logERROR:$ *>& 2; }
    fatal(){error$ *;出口1; }
    $ b $ case $ 1
    refs / tags / *)
    [$ 3!= 0000000000000000000000000000000000000000] \
    ||致命的你不允许删除标签
    [$ 2= 0000000000000000000000000000000000000000] \
    ||致命的你不能移动标签
    ;;
    esac


    I have a central bare repository in which a team publish (push) their commits. In this main repository, I want to disable the tag deletion and renaming.

    Is there a solution like a hook or something ?

    解决方案

    git help hooks contains documentation about the hooks. The update hook is invoked when Git is about to create/move/delete a reference. It is called once per reference to be updated, and is given:

    • 1st argument: the reference name (e.g., refs/tags/v1.0)
    • 2nd argument: SHA1 of the object where the reference currently points (all zeros if the reference does not currently exist)
    • 3rd argument: SHA1 of the object where the user wants the reference to point (all zeros if the reference is to be deleted).

    If the hook exits with a non-zero exit code, git won't update the reference and the user will get an error.

    So to address your particular problem, you can add the following to your update hook:

    #!/bin/sh
    
    log() { printf '%s\n' "$*"; }
    error() { log "ERROR: $*" >&2; }
    fatal() { error "$*"; exit 1; }
    
    case $1 in
        refs/tags/*)
            [ "$3" != 0000000000000000000000000000000000000000 ] \
                || fatal "you're not allowed to delete tags"
            [ "$2" = 0000000000000000000000000000000000000000 ] \
                || fatal "you're not allowed to move tags"
            ;;
    esac
    

    这篇关于禁用标记删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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