fix(git): run post-checkout hook after worktree creation bootstrap (#2721)
Worktrees are created with `git worktree add --no-checkout` and populated with `git reset --hard`, neither of which runs git's post-checkout hook. Invoke the hook explicitly after population with git's standard arguments (null ref previous HEAD, checked-out HEAD, flag 1) and the worktree as cwd, mirroring `git worktree add` without --no-checkout. A missing or non-executable hook is skipped (matching git) and a failing hook is logged as a warning, never failing worktree creation or session bootstrap. Applied to both the web server git service and the VS Code runtime's git service.
This commit is contained in:
@@ -48,7 +48,7 @@ The following functions are exported and used by the web server:
|
||||
### Worktree Operations
|
||||
- `getWorktrees(directory)`: List all git worktrees for a repository.
|
||||
- `validateWorktreeCreate(directory, input)`: Validate worktree creation parameters (mode, branchName, startRef, upstream config).
|
||||
- `createWorktree(directory, input)`: Create a new worktree (supports 'new' and 'existing' modes, upstream setup).
|
||||
- `createWorktree(directory, input)`: Create a new worktree (supports 'new' and 'existing' modes, upstream setup). After populating the worktree, the repository's `post-checkout` hook runs once with git's standard arguments (null ref as previous HEAD, the checked-out HEAD, and flag `1`) from the worktree directory, mirroring `git worktree add` without `--no-checkout`; a missing or non-executable hook is skipped and a failing hook is logged as a warning, never failing worktree creation or the session bootstrap.
|
||||
- `removeWorktree(directory, input)`: Remove a worktree (optionally delete local branch).
|
||||
- `isLinkedWorktree(directory)`: Check if directory is a linked worktree (not primary).
|
||||
|
||||
@@ -95,6 +95,7 @@ The following functions are internal helpers used by exported functions:
|
||||
- `resolveCandidateDirectory(...)`: Generate unique worktree directory candidates.
|
||||
- `resolveBranchForExistingMode(...)`: Resolve branch for existing-mode worktree creation.
|
||||
- `applyUpstreamConfiguration(...)`: Set upstream tracking for new branches.
|
||||
- `runPostCheckoutHook(directory)`: Invoke the worktree's `post-checkout` hook after population, because `git worktree add --no-checkout` and the bootstrap's `git reset --hard` never run git hooks. Runs with git's standard arguments and the worktree as cwd; skips missing/non-executable hooks and never throws on hook failure.
|
||||
- And various other internal helpers for Git command execution and parsing.
|
||||
|
||||
## Response Contracts
|
||||
|
||||
Reference in New Issue
Block a user