git server side hook - only specific branches will be pushed

给你一囗甜甜゛ 提交于 2021-01-28 10:12:30

问题


i' m very newbie to git hooks. I' d like to make sure that to the repository only branches will be pushed / updated which starts with BT. So no update is possible to master / current branch. How can i achieve that? I guess it should be part of the update script, right?


回答1:


It could be a pre-receive hook.

#!/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


来源:https://stackoverflow.com/questions/47201157/git-server-side-hook-only-specific-branches-will-be-pushed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!