fix(git): 切换未跟踪文件显示模式以支持新文件夹内文件差异 (#242)

* fix(git): 切换未跟踪文件显示模式以支持新文件夹内文件差异
当使用 `git status --untracked-files=normal` 时,新文件夹会被折叠为单条 `?? dir/` 条目,点击后因无法读取目录(`fs.read` 报错 "is a directory")而无法加载差异。切换至 `--untracked-files=all` 使新文件夹下的每个文件独立显示为一行,并可正常查看差异,与 VSCode 默认行为一致。同时添加回归测试以验证 porcelain 输出格式。

* test(git): 补真实 git 集成测试钉住 status() 的 --untracked-files=all(review feedback)

---------

Co-authored-by: Menghuan1918 <menghuan2003@outlook.com>
This commit is contained in:
SKX
2026-08-22 23:09:58 +08:00
committed by GitHub
co-authored by Menghuan1918
parent 4148130aac
commit e867e27106
2 changed files with 44 additions and 3 deletions
+9 -2
View File
@@ -143,13 +143,20 @@ export async function currentBranch(cwd: string): Promise<string> {
return out.trim()
}
/** Working-tree status (untracked included). */
/**
* Working-tree status (untracked included). `--untracked-files=all` lists
* the CONTENTS of new directories as individual entries (`?? newdir/a.ts`
* rather than a collapsed `?? newdir/`), so every row in the source-control
* panel is a real file whose diff tab can load. With `=normal`, git folds a
* new folder into one trailing-slash entry that has no diff output and
* cannot be read as a file.
*/
export async function status(cwd: string): Promise<GitStatusResult> {
const repo = await isGitRepo(cwd)
if (!repo) return { isRepo: false, entries: [] }
const [branch, raw] = await Promise.all([
currentBranch(cwd).catch(() => 'HEAD'),
runGit(cwd, ['status', '--porcelain=v1', '-z', '--untracked-files=normal']),
runGit(cwd, ['status', '--porcelain=v1', '-z', '--untracked-files=all']),
])
return { isRepo: true, branch, entries: parsePorcelainZ(raw) }
}