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 / probes / untracked-rows-of / untracked-rows-of.ts
59 lines · 2.0 KBRaw
1import Limits from '../../../limits'
2import type Types from '../../types'
3import { datingsOf } from '../datings-of'
4import type { UntrackedPlace } from '../untracked-place'
5import { wasDirtyAtStart } from '../was-dirty-at-start'
6
7/**
8 * Listed untracked paths as 0/0 rows: the session's own first, then,
9 * when the scope asks, the tagged pre-session ones, up to the slots.
10 *
11 * At most MAX_UNTRACKED_PROBES are dated; a file past that or past the
12 * listing budget reads as pre-session, an undatable one or one that turned
13 * up since the start (wasDirtyAtStart) as the session's (the built-in's).
14 *
15 * @param context the fetch's stamp probe and session start
16 * @param paths the untracked paths, root-relative, as the lister printed them
17 * @param place the free row slots and the scope
18 * @returns the rows to merge after the tracked ones
19 */
20export async function untrackedRowsOf(
21 context: Types.DatingContext,
22 paths: readonly string[],
23 place: UntrackedPlace,
24): Promise<readonly Types.FileStat[]> {
25 const probedPaths = paths.slice(0, Limits.MAX_UNTRACKED_PROBES)
26 const datings = await datingsOf(context, probedPaths)
27
28 const isPreSessionOf = (path: string, dating: Types.Dating | undefined) =>
29 dating === 'unlisted' ||
30 (dating === 'pre-session' && wasDirtyAtStart(context, path))
31
32 const probed = probedPaths.map(path => ({
33 path,
34 isPreSession: isPreSessionOf(path, datings.get(path)),
35 }))
36
37 const isWithPreSession = place.scope === 'with-pre-session'
38
39 const earlier = isWithPreSession
40 ? [
41 ...probed.filter(file => file.isPreSession),
42 ...paths
43 .slice(Limits.MAX_UNTRACKED_PROBES)
44 .map(path => ({ path, isPreSession: true })),
45 ]
46 : []
47
48 const ordered = [...probed.filter(file => !file.isPreSession), ...earlier]
49
50 return ordered.slice(0, place.slots).map(file => ({
51 path: file.path,
52 renamedFrom: null,
53 added: 0,
54 removed: 0,
55 isBinary: false,
56 isUntracked: true,
57 isPreSession: file.isPreSession,
58 }))
59}