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 / tiers / with-untracked / merged-with-untracked / merged-with-untracked.ts
32 lines · 1.2 KBRaw
1import type Types from '../../../types'
2import { mergedResultOf } from '../merged-result-of'
3
4/**
5 * A tier's tracked rows and totals with a listed set of untracked rows
6 * after them, or flagged withheld when the lister gave no whole listing.
7 *
8 * As the built-in's mergeSessionUntrackedFiles merges them, a path a
9 * tracked row already holds keeps that row and counts once.
10 *
11 * @param result the tier's tracked rows and totals
12 * @param untracked the untracked rows, or null when their listing was withheld
13 * @returns the merged rows and totals, and whether the listing was withheld
14 */
15export function mergedWithUntracked(
16 result: Types.NumstatResult,
17 untracked: readonly Types.FileStat[] | null,
18): Types.MergedResult {
19 if (!untracked) {
20 return mergedResultOf(result, { isUntrackedWithheld: true })
21 }
22
23 const tracked = new Set(result.files.map(file => file.path))
24 const fresh = untracked.filter(file => !tracked.has(file.path))
25 const filesCount = result.stats.filesCount + fresh.length
26 const stats = { ...result.stats, filesCount }
27
28 return mergedResultOf(
29 { stats, files: [...result.files, ...fresh] },
30 { isUntrackedWithheld: false },
31 )
32}