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 / backend / backend-of.ts
29 lines · 929 BRaw
1import Git from '../git'
2import type { Backend, BackendHost, BackendProbe } from './types'
3
4/**
5 * The backend holding the session's directory: the first of `probes` that
6 * answers one, else git when a git working tree holds it, else none. The
7 * probes go first so a probe may claim a working copy by its own rule
8 * (the nearer of two markers, say); a probe answers null wherever git
9 * should govern.
10 *
11 * @param host the bound host's runner and probes
12 * @param probes probes for other version-control systems, in order
13 * (INSTALLED_BACKEND_PROBES at the pane; none as published)
14 * @returns the pinned backend, or null outside any working tree
15 */
16export async function backendOf(
17 host: BackendHost,
18 probes: Iterable<BackendProbe>,
19): Promise<Backend | null> {
20 for (const probe of probes) {
21 const backend = await probe(host)
22
23 if (backend) {
24 return backend
25 }
26 }
27
28 return Git.gitBackendOf(host)
29}