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 / hunk-after.ts
20 lines · 664 BRaw
1import { countOf } from '../count-of'
2import type { Hunk } from './types'
3
4/**
5 * The hunk less its first so many lines, its starts moved past them so
6 * the numbers of the lines kept stay right; whole at 0.
7 *
8 * @param hunk the hunk, its lines body lines only
9 * @param count how many leading lines to drop
10 * @returns the rest of the hunk
11 */
12export function hunkAfter(hunk: Hunk, count: number): Hunk {
13 const dropped = hunk.lines.slice(0, count)
14
15 return {
16 oldStart: hunk.oldStart + countOf(dropped, line => !line.startsWith('+')),
17 newStart: hunk.newStart + countOf(dropped, line => !line.startsWith('-')),
18 lines: hunk.lines.slice(count),
19 }
20}