禁用标签删除 [英] Disable tag deletion
问题描述
我有一个中央裸存储库,团队在其中发布(推送)他们的提交.在这个主存储库中,我想禁用标签删除和重命名.
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
包含有关 hooks 的文档.当 Git 即将创建/移动/删除引用时,会调用 update
挂钩.每个要更新的引用调用一次,并给出:
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:
- 第一个参数:引用名称(例如,refs/tags/v1.0)
- 第二个参数:引用当前指向的对象的 SHA1(如果引用当前不存在,则全为零)
- 第三个参数:用户希望引用指向的对象的 SHA1(如果要删除引用,则全为零).
如果钩子以非零退出代码退出,git
不会更新引用并且用户会收到错误.
If the hook exits with a non-zero exit code, git
won't update the reference and the user will get an error.
因此,为了解决您的特定问题,您可以将以下内容添加到您的 update
挂钩中:
So to address your particular problem, you can add the following to your update
hook:
#!/bin/sh
log() { printf '%s
' "$*"; }
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屋!