Add core hooks support and worktree coverage#556
Closed
jwiegley wants to merge 44 commits intogit-ai-project:mainfrom
Closed
Add core hooks support and worktree coverage#556jwiegley wants to merge 44 commits intogit-ai-project:mainfrom
jwiegley wants to merge 44 commits intogit-ai-project:mainfrom
Conversation
|
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
Add hook-name binary dispatch and managed global hooks installation with persisted forward state for previous global/local hooksPath. Add repo-level hook self-heal from checkpoint flow, recursion suppression for internal git subprocesses, and wrapper+hooks coexistence safeguards to avoid double execution. Extend test harness with wrapper/hooks/both modes and add hook mode regression coverage.
Bug fixes: - Cache forward hooks dir lookup in handle_git_hook_invocation to avoid redundant state file reads (was reading twice per hook invocation) - Add is_valid_git_oid_or_abbrev for sequencer done file parsing which may contain abbreviated commit hashes (>= 7 chars) Simplifications: - Extract parse_whitespace_fields to consolidate parse_hook_stdin and parse_reference_transaction_stdin which shared identical parsing logic - Remove 19-line redundant no-op hook match arm in run_managed_hook that duplicated hook_has_no_managed_behavior; wildcard already handles this Tests (18 new unit tests): - is_valid_git_oid: SHA-1, SHA-256, rejects short/invalid - is_valid_git_oid_or_abbrev: abbreviated hex acceptance - parse_reference_transaction_stdin: 3-field extraction, incomplete lines - parse_hook_stdin: single-field skip, extra field handling - parse_whitespace_fields: empty input edge cases - is_path_inside_component: nested segment detection - is_path_inside_any_git_ai_dir: .git/ai subtree detection - hook_has_no_managed_behavior: correct classification - cherry_pick_batch_state: serialization roundtrip - repo_hook_state: serialization roundtrip - forward_mode_none: serialization format - ensure_hook_symlink: idempotency - rebase_hook_mask: double-enable is noop - managed/rebase hook name subset invariants Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
…anaged_behavior, share git_dir lookup, remove dead code, add tests Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
…, fix silent hook breakage in hooks-only mode Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
… original exists in forward dir - Extract sync_non_managed_hook_symlinks to scan forward target dir and only install symlinks for non-managed hooks whose original script exists there - Symlinks point to git-ai binary (not original script) so forwarding preserves $0/dirname for Husky-style hooks that resolve relative paths - Stale symlinks cleaned up when original hook is removed from forward dir - Self-healing via ensure_repo_hooks_installed re-scans and keeps in sync - Extract remove_hook_entry helper to deduplicate cleanup logic - 4 new tests: provisioned-only-when-original-exists, resync cleanup, no-forward-target skips non-managed, forward-target with empty dir Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
bed3a1d to
529ba95
Compare
- Fix long_rev boundary output to show ^<39 hex> = 40 chars (matching git) - Update abbrev test to expect ^<N hex> = N+1 chars for boundary commits Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When `install-hooks` sets global `core.hooksPath` to the managed directory, only hooks listed in INSTALLED_HOOKS previously got shell scripts. Any user hook not in the list (e.g. commit-msg, prepare-commit-msg, pre-merge-commit) was silently lost because git would look for it in the managed directory and find nothing. This commit: 1. Adds commit-msg, prepare-commit-msg, and pre-merge-commit to INSTALLED_HOOKS so the most commonly used hooks get full managed scripts with chaining logic. 2. Adds sync_non_managed_core_hook_scripts() which scans the user's previous hooks directory and writes lightweight passthrough scripts for any remaining hooks not in INSTALLED_HOOKS. Stale passthrough scripts from prior installations are cleaned up automatically. This mirrors what the repo-local hooks mode already does via sync_non_managed_hook_symlinks in git_hook_handlers.rs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40f27dd to
483d595
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core_hooks.rsmodule enabling hook installation viacore.hooksPathas an alternative to wrapper-binary mode, with full lifecycle handling (commit, rebase, reset, stash, push, fetch, cherry-pick, merge, checkout, switch)WorktreeRepo,with_worktree_mode, snapshot variants)GITAI_SKIP_MANAGED_HOOKSandGIT_AI_SKIP_CORE_HOOKSenv vars to prevent hook re-entry in either modeBuilt on top of the
codex/global-hooks-dual-modebranch (repo-local hook management rewrite).Changes
New files
src/commands/core_hooks.rs— Core hooks dispatch and lifecycle management (1,300+ LOC)tests/corehooks_wrapper_regression.rs— Regression tests for dual-mode event recordingtests/worktrees.rs— 850+ LOC worktree integration test suiteModified
src/commands/git_handlers.rs— Set both hook-skip env vars on child processessrc/git/repository.rs— AddGIT_AI_SKIP_CORE_HOOKStoexec_git*functionssrc/commands/install_hooks.rs— Core hooks installation integrationsrc/commands/hooks/stash_hooks.rs— Stash attribution fixes for core hooks modetests/repos/test_repo.rs— Worktree-aware test infrastructure,git_with_env_using_c_flaghelpertests/repos/mod.rs—worktree_test_wrappers!macro for mode-parameterized testsTest plan
cargo checkpassescargo clippypasses cleancargo test --no-runcompiles all test binaries🤖 Generated with Claude Code