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-files / untracked-files.ts
40 lines · 1.1 KBRaw
1import Argv from '../../argv'
2import Parse from '../../parse'
3import type Types from '../../types'
4import type { UntrackedPlace } from '../untracked-place'
5import { untrackedRowsOf } from '../untracked-rows-of'
6
7/**
8 * The untracked, unignored files as 0/0 rows (untrackedRowsOf), listed
9 * with `ls-files -z`. A listing not given whole: no answer.
10 *
11 * @param context the fetch: its pinned git, stamp probe and session start
12 * @param place the free row slots and the scope
13 * @returns the rows to merge after the tracked ones, or null when the
14 * `-z` listing failed, timed out or was cut
15 */
16export async function untrackedFiles(
17 context: Pick<Types.FetchContext, 'run'> & Types.DatingContext,
18 place: UntrackedPlace,
19): Promise<readonly Types.FileStat[] | null> {
20 if (place.slots <= 0) {
21 return []
22 }
23
24 const listing = await context.run([
25 Argv.NO_OPTIONAL_LOCKS,
26 'ls-files',
27 '-z',
28 '--others',
29 '--exclude-standard',
30 '--full-name',
31 ])
32
33 return Parse.isWholeAnswer(listing)
34 ? untrackedRowsOf(
35 context,
36 listing.stdout.split('\0').filter(path => path !== ''),
37 place,
38 )
39 : null
40}