2017-11-09 15 views
1

私はgitフックにはじめての初心者です。私はリポジトリにブランチだけがBTで始まるプッシュ/アップデートされることを確認したいと思います。したがって、マスター/カレントブランチには更新ができません。どうすればそれを達成できますか?私はそれが更新スクリプトの一部でなければならないと思いますよね?gitサーバーサイドフック - 特定のブランチのみがプッシュされます

答えて

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 
+1

このフックは、すべてのタグ名、またはGerritスタイルの 'refs/for/... '名などに対するすべての操作を禁止します。これらを許可するには、' BT'で始まらないブランチを拒否する前に、参照がブランチ名かどうかを確認してください( 'refs/heads /'で始まります)。 – torek

+0

ありがとう、それは正常に動作します。 – user2194805

関連する問題