From 5a8495adb795f27f0ee202b3b5073f9880bd6298 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Thu, 14 May 2026 09:56:36 -0400 Subject: [PATCH] fix(init): preserve inside=true on root lookup failures --- .changeset/3491-nested-git-detection.md | 2 +- sdk/src/query/init-complex.ts | 20 ++++++++++++-------- sdk/src/query/init.ts | 20 ++++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.changeset/3491-nested-git-detection.md b/.changeset/3491-nested-git-detection.md index e82fd1be6..86965205f 100644 --- a/.changeset/3491-nested-git-detection.md +++ b/.changeset/3491-nested-git-detection.md @@ -1,5 +1,5 @@ --- type: Fixed -pr: 3491 +pr: 3502 --- **`/gsd-new-project` and `/gsd-ingest-docs` no longer create a nested `.git` inside an existing worktree (#3491)** — the shallow `has_git: false` check (which only looked for `.git` in the current directory) has been replaced with `git rev-parse --is-inside-work-tree` semantics. The init payload now surfaces `git_worktree_root` and `in_nested_subdir` so the workflows correctly skip `git init` when invoked from a subdirectory of an existing repo and warn that planning files will be tracked by the outer repo. diff --git a/sdk/src/query/init-complex.ts b/sdk/src/query/init-complex.ts index 49f42b0b5..4f7d1473f 100644 --- a/sdk/src/query/init-complex.ts +++ b/sdk/src/query/init-complex.ts @@ -82,14 +82,18 @@ function gitWorktreeInfo(base: string): { inside: boolean; worktreeRoot: string env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, }).trim(); if (inside !== 'true') return { inside: false, worktreeRoot: null }; - const root = execSync('git rev-parse --show-toplevel', { - cwd: base, - stdio: ['ignore', 'pipe', 'ignore'], - encoding: 'utf-8', - timeout: 5000, - env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, - }).trim(); - return { inside: true, worktreeRoot: root || null }; + try { + const root = execSync('git rev-parse --show-toplevel', { + cwd: base, + stdio: ['ignore', 'pipe', 'ignore'], + encoding: 'utf-8', + timeout: 5000, + env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, + }).trim(); + return { inside: true, worktreeRoot: root || null }; + } catch { + return { inside: true, worktreeRoot: null }; + } } catch { return { inside: false, worktreeRoot: null }; } diff --git a/sdk/src/query/init.ts b/sdk/src/query/init.ts index 3e99046bd..c415910f9 100644 --- a/sdk/src/query/init.ts +++ b/sdk/src/query/init.ts @@ -98,14 +98,18 @@ function gitWorktreeInfo(base: string): { inside: boolean; worktreeRoot: string env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, }).trim(); if (inside !== 'true') return { inside: false, worktreeRoot: null }; - const root = execSync('git rev-parse --show-toplevel', { - cwd: base, - stdio: ['ignore', 'pipe', 'ignore'], - encoding: 'utf-8', - timeout: 5000, - env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, - }).trim(); - return { inside: true, worktreeRoot: root || null }; + try { + const root = execSync('git rev-parse --show-toplevel', { + cwd: base, + stdio: ['ignore', 'pipe', 'ignore'], + encoding: 'utf-8', + timeout: 5000, + env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, + }).trim(); + return { inside: true, worktreeRoot: root || null }; + } catch { + return { inside: true, worktreeRoot: null }; + } } catch { return { inside: false, worktreeRoot: null }; }