The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep ignored nested repositories visible (#99861)
MichaelZelbelae29183cad9d
diff --git a/apps/desktop/src/app/right-sidebar/files/ipc.test.ts b/apps/desktop/src/app/right-sidebar/files/ipc.test.tsindex 2892cc47d2b..597af0c8ec3 100644--- a/apps/desktop/src/app/right-sidebar/files/ipc.test.ts+++ b/apps/desktop/src/app/right-sidebar/files/ipc.test.ts@@ -80,7 +80,9 @@ describe('readProjectDir', () => {const result = await readProjectDir('C:\\repo\\src', 'C:\\repo')expect(result.entries.map(entry => entry.name)).toEqual(['keep.ts'])- expect(gitRoot).toHaveBeenCalledWith('C:/repo')+ // The rule lookup anchors at the nearest git root of the LISTED directory,+ // so the bridge is asked about dirPath first (the mock answers with the repo root).+ expect(gitRoot).toHaveBeenCalledWith('C:/repo/src')expect(readFileDataUrl).toHaveBeenCalledWith('C:/repo/.gitignore')})@@ -175,4 +177,103 @@ describe('readProjectDir', () => {expect(result.entries.map(entry => entry.name)).toEqual(['keep.ts'])})++ it('keeps nested repository roots visible when the parent gitignores them', async () => {+ // The bridge strips .git from listings, so repo-ness is detected via gitRoot:+ // a nested repo resolves to itself, an ordinary ignored dir to the parent's root.+ gitRoot.mockImplementation(async path => {+ if (path === '/repo/dev/ownward-studio') {+ return '/repo/dev/ownward-studio'+ }++ return '/repo'+ })+ readDir.mockImplementation(async path => {+ if (path === '/repo') {+ return ok([{ name: '.gitignore', path: '/repo/.gitignore', isDirectory: false }])+ }++ if (path === '/repo/dev') {+ return ok([+ { name: 'ownward-studio', path: '/repo/dev/ownward-studio', isDirectory: true },+ { name: 'scratch', path: '/repo/dev/scratch', isDirectory: true },+ { name: 'notes.txt', path: '/repo/dev/notes.txt', isDirectory: false },+ { name: 'README.md', path: '/repo/dev/README.md', isDirectory: false }+ ])+ }++ return ok([])+ })+ readFileDataUrl.mockResolvedValue(dataUrl('dev/*\n!dev/README.md\n'))++ const result = await readProjectDir('/repo/dev', '/repo')++ expect(result.entries.map(entry => entry.name)).toEqual(['ownward-studio', 'README.md'])+ })++ it('keeps worktree roots (a .git file, not a directory) visible', async () => {+ // A linked worktree is its own toplevel too, so the same git check covers it.+ gitRoot.mockImplementation(async path => {+ if (path === '/repo/dev/wt-feature') {+ return '/repo/dev/wt-feature'+ }++ return '/repo'+ })+ readDir.mockImplementation(async path => {+ if (path === '/repo') {+ return ok([{ name: '.gitignore', path: '/repo/.gitignore', isDirectory: false }])+ }++ if (path === '/repo/dev') {+ return ok([{ name: 'wt-feature', path: '/repo/dev/wt-feature', isDirectory: true }])+ }++ return ok([])+ })+ readFileDataUrl.mockResolvedValue(dataUrl('dev/*\n'))++ const result = await readProjectDir('/repo/dev', '/repo')++ expect(result.entries.map(entry => entry.name)).toEqual(['wt-feature'])+ })++ it('inside a nested repo, only that repo’s own .gitignore governs', async () => {+ // The parent's dev/* must NOT empty the nested repo: the rule chain re-anchors+ // at the nested repo's own root, so only its own .gitignore applies.+ gitRoot.mockImplementation(async path => {+ if (path === '/repo/dev/ownward-studio') {+ return '/repo/dev/ownward-studio'+ }++ return '/repo'+ })+ readDir.mockImplementation(async path => {+ if (path === '/repo') {+ return ok([{ name: '.gitignore', path: '/repo/.gitignore', isDirectory: false }])+ }++ if (path === '/repo/dev/ownward-studio') {+ return ok([+ { name: '.gitignore', path: '/repo/dev/ownward-studio/.gitignore', isDirectory: false },+ { name: 'company-memory', path: '/repo/dev/ownward-studio/company-memory', isDirectory: true },+ { name: 'coverage', path: '/repo/dev/ownward-studio/coverage', isDirectory: true },+ { name: 'README.md', path: '/repo/dev/ownward-studio/README.md', isDirectory: false }+ ])+ }++ return ok([])+ })+ readFileDataUrl.mockImplementation(async path => {+ if (path === '/repo/.gitignore') {+ return dataUrl('dev/*\n')+ }++ return dataUrl('coverage/\n')+ })++ const result = await readProjectDir('/repo/dev/ownward-studio', '/repo')++ expect(result.entries.map(entry => entry.name)).toEqual(['.gitignore', 'company-memory', 'README.md'])+ })})diff --git a/apps/desktop/src/app/right-sidebar/files/ipc.ts b/apps/desktop/src/app/right-sidebar/files/ipc.tsindex 98e98e3171f..9465c27b6e2 100644--- a/apps/desktop/src/app/right-sidebar/files/ipc.ts+++ b/apps/desktop/src/app/right-sidebar/files/ipc.ts@@ -16,6 +16,7 @@ interface GitignoreRule {const gitRootCache = new Map<string, Promise<string | null>>()const gitignoreCache = new Map<string, Promise<GitignoreRule | null>>()+const nestedRepoCache = new Map<string, Promise<boolean>>()function decodeDataUrl(dataUrl: string) {const match = dataUrl.match(/^data:[^,]*,(.*)$/)@@ -106,6 +107,42 @@ async function gitignoreFor(dir: string) {return cached}+/**+ * A directory that is the root of its OWN repository is a nested repo (or worktree) root.+ * Never hide those behind the parent's .gitignore: ignoring them there is exactly how the+ * common repo-inside-repo layout keeps a superproject clean, and hiding them makes real,+ * version-controlled work vanish from the tree with no way to reveal it.+ *+ * Ask git, not the directory listing: the readDir bridge strips `.git` entries+ * (FS_READDIR_HIDDEN in electron/fs-read-dir.ts), so a listing probe finds them in tests+ * (mocked listings) but never in production. `git rev-parse --show-toplevel` answers for+ * any directory, ignored or not: a nested repo resolves to itself, an ordinary ignored+ * directory resolves to the parent's root.+ */+async function isNestedRepoRoot(entry: HermesReadDirEntry): Promise<boolean> {+ if (!entry.isDirectory) {+ return false+ }++ const key = `${desktopFsCacheKey()}:${cleanPath(entry.path)}`+ let cached = nestedRepoCache.get(key)++ if (!cached) {+ cached = (async () => {+ try {+ const root = await desktopGitRoot(cleanPath(entry.path))++ return root !== null && comparisonPath(root) === comparisonPath(entry.path)+ } catch {+ return false+ }+ })()+ nestedRepoCache.set(key, cached)+ }++ return cached+}+function ignoredBy(rules: GitignoreRule[], entry: HermesReadDirEntry) {return rules.some(rule => {const rel = relativeTo(rule.base, entry.path)@@ -126,7 +163,13 @@ async function filterIgnored(entries: HermesReadDirEntry[], rootPath: string, direturn entries}- const root = await gitRootFor(rootPath)+ // Anchor the rule lookup at the nearest repository root of the LISTED directory,+ // not the project root. A parent repo's .gitignore stops at a nested repo's+ // boundary (git applies ignore rules only within their own repository), so+ // inside dev/<repo> only <repo>'s own .gitignore chain governs. Without this,+ // the parent's `dev/*` pattern matches every entry inside the nested repo and+ // the tree shows an empty folder one level down.+ const root = (await gitRootFor(dirPath)) ?? (await gitRootFor(rootPath))if (!root) {return entries@@ -136,7 +179,23 @@ async function filterIgnored(entries: HermesReadDirEntry[], rootPath: string, diBoolean(r))- return rules.length > 0 ? entries.filter(entry => !ignoredBy(rules, entry)) : entries+ if (rules.length === 0) {+ return entries+ }++ // Probe only entries the rules would hide: a nested repo root stays visible,+ // everything else the parent ignores is filtered as before.+ const visible = await Promise.all(+ entries.map(async entry => {+ if (!ignoredBy(rules, entry)) {+ return entry+ }++ return (await isNestedRepoRoot(entry)) ? entry : null+ })+ )++ return visible.filter((entry): entry is HermesReadDirEntry => entry !== null)}export async function readProjectDir(dirPath: string, rootPath = dirPath): Promise<HermesReadDirResult> {@@ -154,6 +213,7 @@ export function clearProjectDirCache(rootPath?: string) {if (!rootPath) {gitRootCache.clear()gitignoreCache.clear()+ nestedRepoCache.clear()return}@@ -161,4 +221,5 @@ export function clearProjectDirCache(rootPath?: string) {const key = `${desktopFsCacheKey()}:${cleanPath(rootPath)}`gitRootCache.delete(key)gitignoreCache.delete(key)+ nestedRepoCache.delete(key)}