有没有办法在接收后在release分支下接受任何分支?

时间:2019-08-27 08:54:17

标签: bash git shell git-post-receive

我当前正在推送到此接受服务器,并且每次创建新版本时,都必须更改代码第4行上接受的BRANCH,我该如何做才能使任何来自发布的内容/被接受了吗?我在考虑类似BRANCH = release / *这样的方法吗?

#!/bin/bash
TARGET="<path_to_site>"
GIT_DIR="<path_to_repo>"
BRANCH="release/1.7"

while read oldrev newrev ref
do
    # only checking out the master (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/$BRANCH ]];
        then
                echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f

        else
                echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
        fi
done

1 个答案:

答案 0 :(得分:0)

您可以在Bash中使用==运算符在if语句中进行正则表达式比较:

if [[ $ref == *"release/"* ]];
then
    # ...
else
    # ...
fi

这将匹配包含字符串"release/"的任何引用,例如"refs/heads/release/1.7"