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 / tests / fixtures / scripted / hunks-answer-of.ts
22 lines · 736 BRaw
1import type { PrintedFile } from './printed-file.js'
2import { rawRecordOf } from './raw-record-of.js'
3
4/**
5 * What git prints for one hunks read: every file's raw record, an empty
6 * field, then every file's patch under its opening line, in the order given.
7 *
8 * @param printed the changed files
9 * @returns the child's standard output, empty when nothing changed
10 */
11export function hunksAnswerOf(printed: readonly PrintedFile[]) {
12 const records = printed.map(([path]) => rawRecordOf(path))
13
14 const patches = printed.map(
15 ([path, body, opening = `diff --git a/${path} b/${path}`]) =>
16 `${opening}\n${body}`,
17 )
18
19 const isEmpty = printed.length === 0
20
21 return isEmpty ? '' : `${records.join('')}\0${patches.join('')}`
22}