spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / git / parse / parse-shortstat.ts
23 lines · 632 BRaw
1import type Types from '../types'
2import { SHORTSTAT_PATTERN } from './shortstat-pattern'
3
4/**
5 * `git diff --shortstat` output as totals, or null when the line is not
6 * git's summary line (empty output for an empty diff included).
7 *
8 * @param stdout the command's standard output
9 * @returns the totals, or null
10 */
11export function parseShortstat(stdout: string): Types.DiffStats | null {
12 const counts = SHORTSTAT_PATTERN.exec(stdout)?.groups
13
14 if (!counts) {
15 return null
16 }
17
18 return {
19 filesCount: Number(counts.files),
20 linesAdded: Number(counts.added ?? 0),
21 linesRemoved: Number(counts.removed ?? 0),
22 }
23}