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