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 / fetch-hunks / with-closing-line / with-closing-line.ts
27 lines · 834 BRaw
1import type Types from '../../types'
2
3/**
4 * A parsed body with one empty context row after its last hunk's lines, as
5 * the built-in panel draws the empty line that closes git's output.
6 *
7 * The built-in reads every file's diff in one piece: the newline before the
8 * next file's header parses as a context line of the file before it. A
9 * body with no hunk, or one already cut, gains nothing.
10 *
11 * @param body the parsed body
12 * @returns the body, its last hunk one row longer
13 */
14export function withClosingLine(body: Types.FileHunks): Types.FileHunks {
15 const last = body.hunks.at(-1)
16 const isClosed = last !== undefined && !body.isTruncated
17
18 return isClosed
19 ? {
20 ...body,
21 hunks: [
22 ...body.hunks.slice(0, -1),
23 { ...last, lines: [...last.lines, ' '] },
24 ],
25 }
26 : body
27}