git服务器端钩子 - 只推送特定的分支

时间:2017-11-09 11:52:13

标签: git githooks repo

我'我是git hooks的新手。我'我想确保在存储库中只推送/更新以BT开头的分支。因此无法更新master / current分支。我怎样才能实现这一目标?我想它应该是更新脚本的一部分,对吧?

1 个答案:

答案 0 :(得分:2)

它可能是pre-receive挂钩。

#!/bin/bash

#sample
z40=0000000000000000000000000000000000000000
while read old new ref;do
    #fail if it's not a branch or the name of the branch does not start with BT
    if [ "${ref:0:13}" != "refs/heads/BT" ];then
        echo "Error: not allowed to update $ref"
        exit 1
    fi

    #deal with other cases if necessary
    #create a ref, branch or tag
    if [ "$old" = "$z40" ];then
        :
    fi

    #delete a ref, branch or tag
    if [ "$new" = "$z40" ];then
        :
    fi
done