You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#!/usr/bin/env bash
set -euo pipefail
repo_root = " $( git rev-parse --show-toplevel 2>/dev/null || true ) "
if [ [ -z " ${ repo_root } " ] ] ; then
echo "错误:当前目录不是 Git 仓库,无法配置 hooks。" >& 2
exit 1
fi
cd " ${ repo_root } "
hooks_dir = ".githooks"
if [ [ ! -d " ${ hooks_dir } " ] ] ; then
echo " 错误:未找到 ${ hooks_dir } 目录,请确认仓库已包含 hooks 文件。 " >& 2
exit 1
fi
git config core.hooksPath " ${ hooks_dir } "
echo "已启用本仓库 Git hooks: " >& 2
echo " core.hooksPath= ${ hooks_dir } " >& 2
echo "" >& 2
echo "现在执行 git commit 时会校验提交信息是否符合:" >& 2
echo " doc/Git Commit Message 规范.md" >& 2
echo "" >& 2
echo "查看当前配置:" >& 2
echo " git config --get core.hooksPath" >& 2
echo "" >& 2
echo "如需取消(恢复默认 .git/hooks) : " >& 2
echo " git config --unset core.hooksPath" >& 2