Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

git - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
' "$*"; }
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...