fix(ssh): detect git repos by ancestry for listFiles fallback

The .git existence check only works at the repo root, not from
subdirectories of a checkout (e.g. /repo/packages/app added as a
folder). Use `git rev-parse --is-inside-work-tree` instead, which
walks up the directory tree and correctly detects git ancestry.
This commit is contained in:
Jinwoo-H
2026-04-24 18:56:54 -04:00
parent 9ef10f80f1
commit 0c4cb77b99
+13 -10
View File
@@ -8,10 +8,10 @@ import {
rename,
cp,
rm,
realpath,
access
realpath
} from 'fs/promises'
import { extname, join } from 'path'
import { extname } from 'path'
import { execFile } from 'child_process'
import type { RelayDispatcher } from './dispatcher'
import type { RelayContext } from './context'
import { expandTilde } from './context'
@@ -233,13 +233,16 @@ export class FsHandler {
if (rgAvailable) {
return listFilesWithRg(rootPath)
}
// Why: git ls-files only works inside git repos. Check for .git first so
// we don't misclassify a git repo with only ignored files as a non-git
// folder — that would surface .gitignore'd files via the readdir fallback.
const isGitRepo = await access(join(rootPath, '.git')).then(
() => true,
() => false
)
// Why: git ls-files only works inside git repos. Use rev-parse to detect
// git ancestry — unlike checking for a local .git entry, this works from
// subdirectories of a checkout (e.g. /repo/packages/app added as a folder).
// Without this, a git subdirectory would fall through to readdir and
// surface .gitignore'd build artifacts.
const isGitRepo = await new Promise<boolean>((resolve) => {
execFile('git', ['rev-parse', '--is-inside-work-tree'], { cwd: rootPath }, (err) =>
resolve(!err)
)
})
if (isGitRepo) {
return listFilesWithGit(rootPath)
}