'use strict'; const fs = require('node:fs'); const path = require('node:path'); const { REPO_ROOT, runCommand } = require('./deploy-lib.cjs'); const HOOKS_DIR = '.githooks'; const HOOK_PATH = path.join(REPO_ROOT, HOOKS_DIR, 'pre-commit'); function main() { if (!fs.existsSync(HOOK_PATH)) { throw new Error(`缺少提交钩子文件: ${HOOK_PATH}`); } runCommand('git', [ 'config', 'core.hooksPath', HOOKS_DIR ], { cwd: REPO_ROOT, stdio: 'inherit' }); console.log(`已设置 core.hooksPath=${HOOKS_DIR}(仓库根: ${REPO_ROOT})`); } try { main(); } catch (err) { console.error(`[ERROR] ${err && err.message ? err.message : err}`); process.exit(1); }