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 / is-transient.ts
38 lines · 1.3 KBRaw
1import type Types from '../types'
2import { REBASE_MARKS } from './rebase-marks'
3import { TRANSIENT_STATE_FILES } from './transient-state-files'
4
5/**
6 * Whether the repository is mid-merge, mid-rebase, mid-cherry-pick or
7 * mid-revert, from a listing of the git directory.
8 *
9 * A state file counts only as a real file and a rebase's folder only as a
10 * real directory, listed once more to tell a rebase's from `git am`'s; a
11 * symbolic link by any of those names is never touched.
12 *
13 * @param entryKindsOf the host's directory listing
14 * @param gitDir the repository's own git directory, absolute
15 * @returns whether a state file, or a rebase's file beside its folder, is there
16 */
17export async function isTransient(
18 entryKindsOf: Types.GitDeps['entryKindsOf'],
19 gitDir: string,
20): Promise<boolean> {
21 const entries = await entryKindsOf(gitDir)
22 const isStopped = entries?.get(REBASE_MARKS.head) === 'file'
23 const isApplying = isStopped && entries?.get(REBASE_MARKS.apply) === 'dir'
24
25 const applied = isApplying
26 ? await entryKindsOf(`${gitDir}/${REBASE_MARKS.apply}`)
27 : null
28
29 const isRebasing =
30 isStopped &&
31 (entries?.get(REBASE_MARKS.merge) === 'dir' ||
32 applied?.get(REBASE_MARKS.rebasing) === 'file')
33
34 return (
35 isRebasing ||
36 TRANSIENT_STATE_FILES.some(file => entries?.get(file) === 'file')
37 )
38}