Files
syops/scripts/install_git_hooks.sh
T
2026-05-21 11:38:54 +08:00

37 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
if ! git -C "${ROOT_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "[hook-install] ${ROOT_DIR} is not a git repository."
exit 1
fi
HOOKS_DIR="${ROOT_DIR}/.githooks"
REQUIRED_HOOKS=(pre-commit pre-push _common.sh)
for hook_name in "${REQUIRED_HOOKS[@]}"; do
hook_path="${HOOKS_DIR}/${hook_name}"
if [[ ! -f "${hook_path}" ]]; then
echo "[hook-install] missing hook file: ${hook_path}"
exit 1
fi
chmod +x "${hook_path}"
done
if ! git -C "${ROOT_DIR}" config core.hooksPath .githooks; then
echo "[hook-install] failed to set git config core.hooksPath."
echo "[hook-install] please run manually in your local shell:"
echo " git config core.hooksPath .githooks"
exit 1
fi
echo "[hook-install] Installed Git hooks successfully."
echo "[hook-install] pre-commit: models 变更需带 migration;frontend 暂存时跑 vue-tsc"
echo "[hook-install] pre-push: 推送含 frontend 变更时跑 npm run build"
echo "[hook-install] core.hooksPath=$(git -C "${ROOT_DIR}" config --get core.hooksPath)"
echo "[hook-install] 跳过前端检查: SKIP_FRONTEND_HOOKS=1"
echo "[hook-install] 跳过全部 hook: SKIP_GIT_HOOKS=1 或 git commit/push --no-verify"