refactor: route status porcelain map parsing through line parser
This commit is contained in:
parent
1f31a3d8f1
commit
b02721463e
@ -1,4 +1,6 @@
|
||||
export type { GitFileStatus, GitFileStat } from "./types"
|
||||
export type { ParsedGitStatusPorcelainLine } from "./parse-status-porcelain-line"
|
||||
export { parseGitStatusPorcelainLine } from "./parse-status-porcelain-line"
|
||||
export { parseGitStatusPorcelain } from "./parse-status-porcelain"
|
||||
export { parseGitDiffNumstat } from "./parse-diff-numstat"
|
||||
export { collectGitDiffStats } from "./collect-git-diff-stats"
|
||||
|
||||
@ -1,24 +1,14 @@
|
||||
import type { GitFileStatus } from "./types"
|
||||
import { parseGitStatusPorcelainLine } from "./parse-status-porcelain-line"
|
||||
|
||||
export function parseGitStatusPorcelain(output: string): Map<string, GitFileStatus> {
|
||||
const map = new Map<string, GitFileStatus>()
|
||||
if (!output) return map
|
||||
|
||||
for (const line of output.split("\n")) {
|
||||
if (!line) continue
|
||||
|
||||
const status = line.substring(0, 2).trim()
|
||||
const filePath = line.substring(3)
|
||||
|
||||
if (!filePath) continue
|
||||
|
||||
if (status === "A" || status === "??") {
|
||||
map.set(filePath, "added")
|
||||
} else if (status === "D") {
|
||||
map.set(filePath, "deleted")
|
||||
} else {
|
||||
map.set(filePath, "modified")
|
||||
}
|
||||
const parsed = parseGitStatusPorcelainLine(line)
|
||||
if (!parsed) continue
|
||||
map.set(parsed.filePath, parsed.status)
|
||||
}
|
||||
|
||||
return map
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user