我发现的唯一解决方案是创建全局自定义挂钩(根据https://docs.gitlab.com/ce/administration/custom_hooks.html和https://stackoverflow.com/a/17064462/2190541)。所以我创建可执行文件gitlab-shell/hooks/pre-receive.d/disable-force-push.sh
,内容如下:
#!/bin/sh
# <oldrev> <newrev> <refname>
# update a blame tree
while read oldrev newrev ref ; do
# old revision is blank - branch creation
if [ "$oldrev" = "0000000000000000000000000000000000000000" ] ||
# new revision is blank - branch deletion
[ "$newrev" = "0000000000000000000000000000000000000000" ] ;
then
# create new or delete old branch
continue;
fi
base=$(git merge-base $oldrev $newrev);
if [ "$base" != "$oldrev" ] ; then
# non fast forward merge
echo "Force pushing of $ref is forbidden";
exit 1;
fi
done
exit 0;
不能完全确定,如果有一个简单的解决方案,但是这将是值得考虑看看:https://docs.gitlab.com/ee /user/permissions.html – ninge
@ninge,是的,我已阅读此页面。但从我看来,强制推送和移除分支的权限是相同的(对于受保护和不受保护的分支)。我没有找到任何方法来改变它。我想念什么? –