【发布时间】:2020-08-22 12:34:25
【问题描述】:
我想要做的是我想将我的钩子添加到服务器中的 repo,以便克隆 repo 的人在推送到 Gitlab 服务器之前通过它。 到目前为止,我所做的是,在 /.git/custom_hooks 的 custom_hooks 文件夹中创建了 pre-receive 文件,并向其中添加了一些脚本。 以下是我的预收文件。
#!/bin/bash
zero_commit="0000000000000000000000000000000000000000"
excludeExisting="--not --all"
while read oldrev newrev refname; do
# echo "payload"
echo $refname $oldrev $newrev
# branch or tag get deleted
if [ "$newrev" = "$zero_commit" ]; then
continue
fi
# Check for new branch or tag
if [ "$oldrev" = "$zero_commit" ]; then
span=`git rev-list $newrev $excludeExisting`
else
span=`git rev-list $oldrev..$newrev $excludeExisting`
fi
for COMMIT in $span;
do
for FILE in `git log -1 --name-only --pretty=format:'' $COMMIT`;
do
echo "rejecting all pushes"
exit 1
done
done
done
exit 0
然后我在本地 Windows 机器上克隆了 repo 并尝试推送它。但它没有产生预期的效果。它仍然被推送到服务器。
我是 Gitlab 和 Git Hooks 的新手。我不知道我的 pre-receive 文件是否错误或哪里出错了。请让我如何向服务器添加挂钩,以便它验证/适用于克隆我的仓库的人。 请帮忙。 提前致谢。
【问题讨论】:
标签: bash gitlab githooks git-push git-clone