【发布时间】:2026-01-20 12:50:01
【问题描述】:
我正在尝试添加一个服务器端检查,该检查将从 git push 触发 - 检查提交的代码/差异是否格式正确。 客户端存在代码格式化程序(Eclipse Code Formatter),这是最后的检查。 到目前为止,我遇到的 pre-receive hook 和 update hook 的例子很少。
#!/usr/bin/env bash
# Git update hook servers side, also doing and checking formatting of code
# check each branch being pushed
# Exit status 0 = all OK
# Exit status 1 = Problem, commit will be rejected
echo "update hook initiated"
# get different values (They are default - from update hook)
ref_name=$1
old_rev=$2
new_rev=$3
# only check branches, not tags or bare commits
#if [ -z $(echo $ref_name | grep "refs/heads/") ]; then
# exit 0
#fi
# don't check empty branches
if [ "$(expr "${new_rev}" : '0*$')" -ne 0 ]; then
exit 0
fi
仅执行失败:
remote: : Permission denied
remote: error: hook declined to update refs/heads/master
任何指针都会很棒!
【问题讨论】:
-
钩子是否驻留在
.git/hooks/update的服务器端?脚本可执行吗? -
是的,它位于您提到的位置。是的,它是可执行的。