fix(git-worktree): compute real line counts for untracked files in diff stats
This commit is contained in:
@@ -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")
|
||||
: ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user