我们使用的是 GitLab 8.5.0 版。我正在编写一个自定义服务器端更新 Hook 来锁定特定的分支。它工作得很好,但是,我想允许处理 GitLab merge 请求。所有 GitLab merge 请求通常在提交描述中都有“查看 merge 请求”注释。因此,我认为只允许那些包含提交消息“查看 merge 请求”的提交。但是,它并不像我想的那样工作。
任何其他可能的方法只允许 gitlab merge 请求?
#!/usr/bin/env bash
GIT_COMMIT_MSG=`git log -1 HEAD --pretty=format:%s`
if [[ "$1" == refs/heads/master ]]; then
if [[ "$GIT_COMMIT_MSG" =~ *"See Merge request"* ]]; then
echo "This is GitLab Merge Request"
else
echo $GIT_COMMIT_MSG
echo "ERROR: you are not allowed to update master" >&2
exit 1
fi
fi
最佳答案
我知道您使用的是 GitLab 8.5,但如果可能,请考虑升级到 8.11,该版本已在本地(并且更安全地)实现。
参见“Using the Allowed to merge and Allowed to push settings”
You could set "
Allowed to push
" to "No one
", and "Allowed to merge
" to "Developers + Masters
", to require everyone to submit a merge request for changes going into the protected branch.
那么你只需要保护一些分支,它们只会通过 merge 请求进行修改。
关于git - 锁定分支但允许 gitlab merge 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40702087/