Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(workspace): a submodule inside a worktree is not a worktree boundary
KageBinary733cda9b462c
diff --git a/ix-cli/src/cli/__tests__/map-root.test.ts b/ix-cli/src/cli/__tests__/map-root.test.tsindex b640ed8f..52310535 100644--- a/ix-cli/src/cli/__tests__/map-root.test.ts+++ b/ix-cli/src/cli/__tests__/map-root.test.ts@@ -235,6 +235,40 @@ describe("nested linked worktrees", () => {expect(findWorkspaceForCwd(clone)?.workspace_id).toBe("ws-0");});+ it("ingests a file in a nested worktree into the worktree, not the enclosing repo", () => {+ const { wt } = repoWithWorktree(join(".claude", "worktrees", "i"));+ expect(resolveIngestRoot(join(wt, "a.ts"), false)).toBe(wt);+ });++ it("treats a sibling worktree as unmapped while only the main checkout is registered", () => {+ const { wt } = repoWithWorktree(join("..", `sibling-${Date.now()}`));+ fixtures.push(wt);+ expect(findWorkspaceForCwd(wt)).toBeUndefined();+ expect(resolveMapRoot(undefined, wt)).toBe(wt);+ });++ it("keeps a real submodule, in the main checkout and in a registered worktree, in its workspace", () => {+ const upstream = realpathSync.native(fixture());+ const git = (cwd: string, ...args: string[]) =>+ execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", "-c", "protocol.file.allow=always", ...args], { cwd, stdio: "ignore" });+ git(upstream, "init", "-q", "-b", "main");+ git(upstream, "commit", "-q", "--allow-empty", "-m", "sub");++ const { repo } = repoWithWorktree(join(".claude", "worktrees", "s"));+ git(repo, "submodule", "add", "-q", upstream, join("libs", "sub"));+ git(repo, "commit", "-q", "-m", "submodule");+ // A worktree created after the submodule, so it checks the submodule out+ // too. Its .git file points into .git/worktrees/<wt>/modules/, which is+ // still a submodule and not a worktree boundary.+ const wt = join(repo, ".claude", "worktrees", "t");+ git(repo, "worktree", "add", "-q", "-b", "with-sub", wt);+ git(wt, "submodule", "update", "--init", "-q");+ register(repo, realpathSync.native(wt));++ expect(findWorkspaceForCwd(join(repo, "libs", "sub"))?.workspace_id).toBe("ws-0");+ expect(findWorkspaceForCwd(join(wt, "libs", "sub"))?.workspace_id).toBe("ws-1");+ });+it("still answers for the main checkout and its subdirectories", () => {const { repo } = repoWithWorktree(join(".claude", "worktrees", "w"));expect(findWorkspaceForCwd(repo)?.workspace_id).toBe("ws-0");diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.tsindex ff6169a6..0b1d5563 100644--- a/ix-cli/src/cli/config.ts+++ b/ix-cli/src/cli/config.ts@@ -328,16 +328,20 @@ export function isReadablePath(candidate: string, explicitRoot?: string): boolea/*** Is `dir` the root of a linked git worktree (`git worktree add`)? Its `.git`- * is a file pointing into the main repository's `.git/worktrees/<name>`. A- * submodule's `.git` file points into `.git/modules/` instead and is not one:- * a submodule is part of the repository that contains it.+ * is a file pointing at the main repository's `.git/worktrees/<name>`, a git+ * directory that holds a `commondir` file -- git's own mark of a linked+ * worktree. A submodule's `.git` file points at a full git directory with no+ * `commondir`, even when it lives under `.git/worktrees/<wt>/modules/` (a+ * submodule checked out in a worktree), and is not one: a submodule is part+ * of the repository that contains it.*/export function isLinkedWorktreeRoot(dir: string): boolean {try {// Read, not stat-then-read: a .git directory throws EISDIR here, which is// the "not a linked worktree" answer anyway.const gitdir = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync(join(dir, ".git"), "utf-8"))?.[1];- return !!gitdir && /[\\/]worktrees[\\/]/.test(gitdir);+ // Relative when written with worktree.useRelativePaths (git 2.48+).+ return !!gitdir && existsSync(join(resolvePath(dir, gitdir), "commondir"));} catch {return false;}