fix: allow nested worktree paths in pre-merge hook regex (#2401) (#2411)

The worktree path regex in pre-merge-check.ts used [^\s/]+ which only
matched a single path segment after /tmp/spawn-worktrees/. This blocked
PR merges from nested worktrees like refactor/fix/issue-N used by the
automated refactoring service.

Fix both the TypeScript regex ([^\s/]+ -> [^\s]+) and the inline bash
grep pattern in settings.json ([a-zA-Z0-9._-]+ -> [a-zA-Z0-9._/-]+).

Closes #2401

Agent: code-health

Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
A 2026-03-09 20:02:30 -07:00 committed by GitHub
parent c4ae16849d
commit d584cc4d4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -29,7 +29,7 @@ function fail(msg: string): never {
// Find repo root — try extracting a worktree path from the command, else use git
let repoRoot: string;
const worktreeMatch = command.match(/\/tmp\/spawn-worktrees\/[^\s/]+/);
const worktreeMatch = command.match(/\/tmp\/spawn-worktrees\/[^\s]+/);
if (worktreeMatch) {
repoRoot = worktreeMatch[0];
} else {

View file

@ -30,7 +30,7 @@
"hooks": [
{
"type": "command",
"command": "bash -c 'INPUT=$(cat); CMD=$(echo \"$INPUT\" | jq -r \".tool_input.command // empty\"); echo \"$CMD\" | grep -qE \"gh pr (merge|ready)\" || exit 0; WT=$(echo \"$CMD\" | grep -oE \"/tmp/spawn-worktrees/[a-zA-Z0-9._-]+\" | head -1); if [ -n \"$WT\" ] && [ -d \"$WT/packages/cli\" ]; then ROOT=\"$WT\"; else ROOT=$(git rev-parse --show-toplevel 2>/dev/null); fi; if [ -z \"$ROOT\" ] || [ ! -d \"$ROOT/packages/cli\" ]; then echo \"WARNING: Could not find spawn repo for pre-merge checks\" >&2; exit 0; fi; cd \"$ROOT/packages/cli\" || exit 2; echo \"Pre-merge gate: running biome check + bun test in $ROOT/packages/cli ...\" >&2; bunx @biomejs/biome check src/ 2>&1 || { echo \"BLOCKED: biome check failed — fix lint/format issues before merging\" >&2; exit 2; }; bun test 2>&1 || { echo \"BLOCKED: tests failed — fix failures before merging\" >&2; exit 2; }; echo \"Pre-merge checks passed\" >&2'"
"command": "bash -c 'INPUT=$(cat); CMD=$(echo \"$INPUT\" | jq -r \".tool_input.command // empty\"); echo \"$CMD\" | grep -qE \"gh pr (merge|ready)\" || exit 0; WT=$(echo \"$CMD\" | grep -oE \"/tmp/spawn-worktrees/[a-zA-Z0-9._/-]+\" | head -1); if [ -n \"$WT\" ] && [ -d \"$WT/packages/cli\" ]; then ROOT=\"$WT\"; else ROOT=$(git rev-parse --show-toplevel 2>/dev/null); fi; if [ -z \"$ROOT\" ] || [ ! -d \"$ROOT/packages/cli\" ]; then echo \"WARNING: Could not find spawn repo for pre-merge checks\" >&2; exit 0; fi; cd \"$ROOT/packages/cli\" || exit 2; echo \"Pre-merge gate: running biome check + bun test in $ROOT/packages/cli ...\" >&2; bunx @biomejs/biome check src/ 2>&1 || { echo \"BLOCKED: biome check failed — fix lint/format issues before merging\" >&2; exit 2; }; bun test 2>&1 || { echo \"BLOCKED: tests failed — fix failures before merging\" >&2; exit 2; }; echo \"Pre-merge checks passed\" >&2'"
}
]
}