fix(git-worktree): compute real line counts for untracked files in diff stats

This commit is contained in:
YeonGyu-Kim
2026-02-09 11:36:35 +09:00
parent 7fdba56d8f
commit edc3317e37
2 changed files with 29 additions and 3 deletions
@@ -30,7 +30,24 @@ export function collectGitDiffStats(directory: string): GitFileStat[] {
? untrackedOutput
.split("\n")
.filter(Boolean)
.map((filePath) => `0\t0\t${filePath}`)
.map((filePath) => {
try {
const wcOutput = execFileSync("wc", ["-l", "--", filePath], {
cwd: directory,
encoding: "utf-8",
timeout: 5000,
stdio: ["pipe", "pipe", "pipe"],
}).trim()
const [lineCountToken] = wcOutput.split(/\s+/)
const lineCount = Number(lineCountToken)
if (!Number.isFinite(lineCount)) return `0\t0\t${filePath}`
return `${lineCount}\t0\t${filePath}`
} catch {
return `0\t0\t${filePath}`
}
})
.join("\n")
: ""