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 / dirty-paths-of / dirty-paths-of.ts
35 lines · 1.1 KBRaw
1import Argv from '../../argv'
2import Parse from '../../parse'
3import type Types from '../../types'
4import { STATUS_PATH_OFFSET } from './status-path-offset'
5
6/**
7 * Every path dirty in the working tree right now, tracked changes and
8 * untracked files alike, as `git status -z` lists them; null unread.
9 *
10 * Read once when the backend is pinned, so a fetch can tell a path that
11 * was already dirty when the session began from one that turned up since
12 * (GitDeps `baseline`). Renames are not paired: each side is its own path.
13 *
14 * @param run runs git against the pinned repository
15 * @returns the paths, root-relative, or null on a failed or cut listing
16 */
17export async function dirtyPathsOf(
18 run: Types.GitRun,
19): Promise<ReadonlySet<string> | null> {
20 const listing = await run([
21 Argv.NO_OPTIONAL_LOCKS,
22 'status',
23 '--porcelain',
24 '-z',
25 '--untracked-files=all',
26 '--no-renames',
27 '--ignore-submodules=dirty',
28 ])
29
30 const records = listing.stdout.split('\0').filter(record => record !== '')
31
32 return Parse.isWholeAnswer(listing)
33 ? new Set(records.map(record => record.slice(STATUS_PATH_OFFSET)))
34 : null
35}