← 教程列表
news

Hooks Awareness

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 9 阅读

Git worktrees do not inherit the parent repo's hooks directory. After creating the worktree, symlink hooks from the main repo if they exist: ```bash MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel) if [ -d "$MAIN_ROOT/.git/hooks" ]; then ln -sf "$MAIN_ROOT/.git/hooks" "$path/.git/hooks" fi ``` This prevents pre-commit checks, linters, and other hooks from silently stopping when work moves to a worktree. **Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), treat this as a restricted environment. Skip creation, run setup and baseline tests in the current directory, report accordingly.

← 返回教程列表 AI8899 · 内容仅供学习参考