git - 锁定分支但允许 gitlab merge 请求

标签 git gitlab githooks

我们使用的是 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.

enter image description here

那么你只需要保护一些分支,它们只会通过 merge 请求进行修改。

关于git - 锁定分支但允许 gitlab merge 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40702087/

相关文章:

drupal - Ubercart 和 Drupal 7 - hook_add_to_cart

git - 自定义 commitlint header 格式

bash - Git Hook : '.git/hooks/pre-commit' : Operation not permitted

git - 使用 GIT_PS1_SHOWCOLORHINTS 自定义 __git_ps1 的颜色

javascript - Heroku Git Push Master 错误

git - 获取错误的 repo 后修复 Git 历史

python - 如何从 gitlab CI 工件文件夹发布覆盖率报告?

gitlab - 获取最新版本的 gitlab 文件存档

c - 什么时候需要调用 git_remote_update_tips?

gitlab - 如何更改 GitLab 中的项目所有者