user2194805
user2194805

Reputation: 1369

git server side hook - only specific branches will be pushed

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?

Upvotes: 1

Views: 406

Answers (1)

ElpieKay
ElpieKay

Reputation: 30858

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

Upvotes: 2

Related Questions