From 3002bd73e0cb29ea36dee6ddb49d4e2cce0fbb8b Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 25 May 2026 10:19:54 -0400 Subject: [PATCH] fix: respect git add option terminator --- hooks/gsd-workflow-guard.js | 1 + tests/bug-261-worktree-force-add-guard.test.cjs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hooks/gsd-workflow-guard.js b/hooks/gsd-workflow-guard.js index e5f3fe6bb..e786c6e8b 100644 --- a/hooks/gsd-workflow-guard.js +++ b/hooks/gsd-workflow-guard.js @@ -46,6 +46,7 @@ function forceGitAddCwds(command, defaultCwd) { if (tokens[j] !== 'add') continue; for (let k = j + 1; k < tokens.length && !separators.has(tokens[k]); k++) { + if (tokens[k] === '--') break; if (tokens[k] === '--force' || tokens[k] === '-f' || /^-[A-Za-z]*f[A-Za-z]*$/.test(tokens[k])) { cwdList.push(gitCwd); break; diff --git a/tests/bug-261-worktree-force-add-guard.test.cjs b/tests/bug-261-worktree-force-add-guard.test.cjs index 273b0d966..75ff70b7a 100644 --- a/tests/bug-261-worktree-force-add-guard.test.cjs +++ b/tests/bug-261-worktree-force-add-guard.test.cjs @@ -89,6 +89,18 @@ describe('bug #261: workflow guard blocks forced git add on worktree-agent branc } }); + test('allows pathspecs named like force flags after git add -- terminator', () => { + const dir = makeRepo('worktree-agent-d4'); + try { + setWorkflowGuard(dir, true); + const result = runBashHook(dir, 'git add -- -f'); + assert.strictEqual(result.status, 0); + assert.strictEqual(result.stdout, ''); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } + }); + test('allows git add -f outside worktree-agent branches', () => { const dir = makeRepo('feature-docs'); try { @@ -102,7 +114,7 @@ describe('bug #261: workflow guard blocks forced git add on worktree-agent branc }); test('allows git add -f on worktree-agent branch when workflow guard is disabled', () => { - const dir = makeRepo('worktree-agent-d4'); + const dir = makeRepo('worktree-agent-e5'); try { setWorkflowGuard(dir, false); const result = runBashHook(dir, 'git add -f .planning/SUMMARY.md'); @@ -114,7 +126,7 @@ describe('bug #261: workflow guard blocks forced git add on worktree-agent branc }); test('allows git add -f on worktree-agent branch when no GSD config exists', () => { - const dir = makeRepo('worktree-agent-e5'); + const dir = makeRepo('worktree-agent-f6'); try { const result = runBashHook(dir, 'git add -f .planning/SUMMARY.md'); assert.strictEqual(result.status, 0);