mirror of
https://github.com/anthropics/claude-code.git
synced 2026-09-14 19:48:39 +08:00
24 lines
632 B
TypeScript
24 lines
632 B
TypeScript
import type Types from '../types'
|
|
import { SHORTSTAT_PATTERN } from './shortstat-pattern'
|
|
|
|
/**
|
|
* `git diff --shortstat` output as totals, or null when the line is not
|
|
* git's summary line (empty output for an empty diff included).
|
|
*
|
|
* @param stdout the command's standard output
|
|
* @returns the totals, or null
|
|
*/
|
|
export function parseShortstat(stdout: string): Types.DiffStats | null {
|
|
const counts = SHORTSTAT_PATTERN.exec(stdout)?.groups
|
|
|
|
if (!counts) {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
filesCount: Number(counts.files),
|
|
linesAdded: Number(counts.added ?? 0),
|
|
linesRemoved: Number(counts.removed ?? 0),
|
|
}
|
|
}
|