Skip to content

core/src/git

git, read (#453) — THE one way Enso runs git: the run-context recorder’s revision probe (#435) and the web server’s GET /api/threads/:threadId/git both come through runGitIn. readGitState turns a cwd into an EnsoGitState, the last-push baseline included; readGitChanges lists every file that differs from that baseline, with its patch (#452); readGitFileTexts reads one of them whole, on both sides, for the Diff view to expand (#461).

⚠ GIT IN THE GIVEN CWD, NOT THE ENVIRONMENT’S REPOSITORY. git honours an inherited GIT_DIR / GIT_WORK_TREE / GIT_INDEX_FILE over its working directory, and git exports them to every hook — so a server started from a hook’s shell would read the hook’s repository for every session. The repository-locating variables are removed from the child’s environment; found under a worktree’s pre-commit gate (#435).

⚠ READ-ONLY, AND NOTHING THE REPOSITORY CONFIGURES RUNS. Every command here only reads. The agent works in the same tree and may be running git itself, so no query takes an optional lock (GIT_OPTIONAL_LOCKS=0 — status would otherwise refresh the index under index.lock). A repository’s own config can name programs git runs on a read, and the agent can write .git/config: core.fsmonitor runs on every status, and a clean or process filter runs on every worktree file an attribute maps to it, whenever status or diff hashes that file (#901). So core.fsmonitor is forced off on the command line, every filter driver the config defines is emptied (filterDriverOverrides), the pager is cat and no prompt waits on a terminal.

⚠ THE COST OF EMPTIED FILTERS: a filtered file is read as its worktree bytes, not as the filter would store it. A Git LFS file is listed as changed and diffs as its content against its committed pointer, and a file an ident-like or formatting filter rewrites shows the rewrite as a change. Every other attribute still applies (eol/text, -diff/binary, diff=<driver> hunk headers) — the reason this does not read attributes from an empty tree (--attr-source), which also leaves .git/info/attributes in force. ⚠ One window stays open: a driver the agent defines between the config read and the command it guards is not emptied for that one command.

⚠ BOUNDED. Each query is killed after GIT_TIMEOUT_MS; a killed or unstartable git is a code of -1, which a reader turns into unavailable, never a hang.

⚠ node-only (node:child_process, node:fs): a subpath, @enso/core/git, never the barrel.

Defined in: packages/core/src/git.ts:286

git answering a read with a failure — its words, or that it never ran or answered in time — as the read throws it: a caller may refuse this, and let any other fault of the read throw on.

  • Error

new GitReadError(message?): GitReadError

Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080

string

GitReadError

Error.constructor

new GitReadError(message?, options?): GitReadError

Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080

string

ErrorOptions

GitReadError

Error.constructor

new GitReadError(message?, options?): GitReadError

Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080

string

ErrorOptions

GitReadError

Error.constructor

readonly name: "GitReadError" = 'GitReadError'

Defined in: packages/core/src/git.ts:287

Error.name


Defined in: packages/core/src/git.ts:877

A changed file’s two paths: now, and at the baseline when it was renamed or copied.

readonly oldPath: string | null

Defined in: packages/core/src/git.ts:879

readonly path: string

Defined in: packages/core/src/git.ts:878


Defined in: packages/core/src/git.ts:887

A changed file’s two sides, each its text or why not.

readonly newText: { kind: "text"; text: string; } | { kind: "none"; } | { bytes: number; kind: "too-large"; } | { kind: "binary"; } | { kind: "unavailable"; reason: string; }

Defined in: packages/core/src/git.ts:889

readonly oldText: { kind: "text"; text: string; } | { kind: "none"; } | { bytes: number; kind: "too-large"; } | { kind: "binary"; } | { kind: "unavailable"; reason: string; }

Defined in: packages/core/src/git.ts:888


Defined in: packages/core/src/git.ts:906

Where readFileTexts reads a changed file: from root, the old side at base — null before the first commit, where there is no old side — and the new side in the work tree.

readonly base: string | null

Defined in: packages/core/src/git.ts:908

readonly listed: (path) => Promise<WorkTreeListing>

Defined in: packages/core/src/git.ts:913

Whether the work tree’s path is a file the changes may list — tracked, or untracked and not ignored. One that is not is never read: an ignored .env is no more shown than listed.

string

Promise<WorkTreeListing>

readonly root: string

Defined in: packages/core/src/git.ts:907


Defined in: packages/core/src/git.ts:144

Where a git runs and what bounds it: its directory, its whole environment, and the timeout and output size past which it is killed (code -1).

readonly cwd: string

Defined in: packages/core/src/git.ts:145

readonly env: ProcessEnv

Defined in: packages/core/src/git.ts:146

readonly maxBuffer: number

Defined in: packages/core/src/git.ts:148

readonly timeout: number

Defined in: packages/core/src/git.ts:147


Defined in: packages/core/src/git.ts:188

A repository git is pointed at rather than finds from its cwd: a bare gitDirectory, the workTree it holds the files of and the index it reads — a thread’s snapshot store (snapshot-store.ts).

readonly gitDirectory: string

Defined in: packages/core/src/git.ts:189

readonly index: string

Defined in: packages/core/src/git.ts:191

readonly workTree: string

Defined in: packages/core/src/git.ts:190


Defined in: packages/core/src/git.ts:72

What a git query answered. code is git’s exit code, or -1 when git could not be started or was killed at the timeout.

readonly code: number

Defined in: packages/core/src/git.ts:73

readonly stderr: string

Defined in: packages/core/src/git.ts:75

readonly stdout: string

Defined in: packages/core/src/git.ts:74


Defined in: packages/core/src/git.ts:769

What readTreeChanges compares: the work tree at root — the files under scope, '' for all of them — against base, a commit or tree, with the files there git does not track as listUntracked names them.

readonly base: string

Defined in: packages/core/src/git.ts:772

readonly listUntracked: () => Promise<readonly string[]>

Defined in: packages/core/src/git.ts:777

The untracked files under scope, relative to root, asked after the tracked diff. Throws when they cannot be listed: no list is not an empty one — the view would say nothing differs.

Promise<readonly string[]>

readonly root: string

Defined in: packages/core/src/git.ts:770

readonly scope: string

Defined in: packages/core/src/git.ts:771


GitRunner = (args, cwd) => Promise<GitResult>

Defined in: packages/core/src/git.ts:83

Runs git with args in cwd — the seam a test replaces.

readonly string[]

string

Promise<GitResult>


WorkTreeListing = "listed" | "not-listed" | { failed: string; }

Defined in: packages/core/src/git.ts:898

Whether the work tree’s file is one the changes may list: listed, not listed (ignored), or the listing failed, in git’s or the store’s words.


const GIT_TIMEOUT_MS: 5000 = 5000

Defined in: packages/core/src/git.ts:58

How long one git query may take.


const runGit: GitRunner

Defined in: packages/core/src/git.ts:264

git under this process’s environment — the runner production uses. The environment is read per call (the quarantine may have scrubbed it since load), and is on the environment allowlist (scripts/lint/process-environment.ts) as the seam itself: every other caller injects one.


const UNTRACKED_DIFF_CONCURRENCY: 8 = 8

Defined in: packages/core/src/git.ts:741

How many untracked files are diffed at once (#463). One git process per file, one after another, cost about 1.5 ms each: 757 ms for 500 files, on every refresh of an open Changes view. Bounded, so a tree of 500 new files never starts 500 processes. Exported for the test that orders the answers against this limit.


execGit(args, bounds): object

Defined in: packages/core/src/git.ts:159

git with args under bounds, settled as a GitResult: a git that fails is its exit code, never a throw. Every git core runs goes through here — the read-only queries below, the snapshot store’s and the thread trees’ runners, each with its own config and bounds. child is for the runner that writes git’s stdin (the snapshot store’s).

readonly string[]

GitBounds

object

readonly child: ChildProcess

readonly result: Promise<GitResult>


gitChildEnvironment(): ProcessEnv

Defined in: packages/core/src/git.ts:274

The environment a git child runs under, as runGit gives it: this process’s, without git’s repository-locating variables. For a caller that spawns git itself, synchronously (the arena’s recorder, score and report). ⚠ Under a git hook — a commit’s gate — GIT_DIR and GIT_INDEX_FILE name the hook’s repository, and a git in any other directory would read it.

ProcessEnv


isPathInScope(scope, path): boolean

Defined in: packages/core/src/git.ts:867

Whether path names a file under scope and nothing else (#461): relative to the root, /-separated, no empty, . or .. segment, no NUL, and starting with scope — '' for the whole tree, else /-ended (EnsoGitRepository’s scope). ⚠ THE LIMIT #456 SET, held for a file the page names: a project inside a dotfiles repository at $HOME reads its own files, never another file under home.

string

string

boolean


readCommitChanges(runGit, place): Promise<{ files: object[]; truncated: boolean; }>

Defined in: packages/core/src/git.ts:677

Every file that differs between two commits of the repository runGit reads, from to to (#553): the work tree is not looked at, so the answer is the two commits’ alone, however the tree has moved since. Each with its patch while the answer has room (MAX_* above). Throws, with git’s words, when either commit cannot be read.

GitRunner

string

string

string

Promise<{ files: object[]; truncated: boolean; }>


readCommitFileTexts(runGit, place, paths): Promise<ChangedFileTexts>

Defined in: packages/core/src/git.ts:694

One file that differs between two commits, whole on both sides (#553): the old side at from, read from oldPath for a rename or copy, the new side at to — both from the repository’s objects, never the work tree. ⚠ The caller holds both paths to the tree first (isPathInScope).

GitRunner

string

string

string

ChangedFilePaths

Promise<ChangedFileTexts>


readFileTexts(runGit, place, paths): Promise<ChangedFileTexts>

Defined in: packages/core/src/git.ts:1017

One changed file whole, on both sides (#461): the old side at place.base, read from oldPath for a rename or copy, and the new side in the work tree — what the Diff view expands the lines between hunks from. Each side is its text, or why not: none there, too large, binary, unreadable. ⚠ The caller holds both paths to the scope first (isPathInScope); this reads what it is given.

GitRunner

FileTextPlace

ChangedFilePaths

Promise<ChangedFileTexts>


readGitChanges(runGit, repository): Promise<{ files: object[]; truncated: boolean; }>

Defined in: packages/core/src/git.ts:827

Every file under repository.scope that differs from its baseline commit — commits not yet pushed, staged and unstaged edits, deletions, renames — and every untracked file there, each with its patch while the answer has room (MAX_* above). ⚠ Only the scope: a project inside a larger repository (a dotfiles repository at $HOME) sends its own files, never its neighbours’. Run from the repository’s root, so every path is the root’s. A baseline of none (no commit yet) compares with the empty tree.

GitRunner

number = Count

Commits on HEAD that baseline.ref does not have; 0 when there is no ref.

{ commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; } = EnsoGitBaseline

string | null = ...

The baseline commit — the merge-base with ref, or HEAD; null for none.

string | null = ...

The remote-tracking ref, short (origin/feature-x); null for head and none.

"head" | "upstream" | "remote-branch" | "remote-default" | "none" = EnsoGitBaselineRule

number = Count

Commits on baseline.ref that HEAD does not have; 0 when there is no ref.

string | null = ...

The checked-out branch, short; null when HEAD is detached.

{ conflicted: number; staged: number; unstaged: number; untracked: number; } = ...

Files under scope by where their changes sit (git status); one file can be staged and unstaged.

number = Count

number = Count

number = Count

number = Count

string | null = ...

HEAD’s commit; null before the first commit.

"repository" = ...

"merge" | "rebase" | "cherry-pick" | "revert" | "bisect" | null = ...

string = ...

The working tree’s top level (git rev-parse --show-toplevel).

string = ...

Where the cwd sits in the working tree (git rev-parse --show-prefix): '' at the top level, else a /-ended path. changes and the changed files are this directory’s alone; the commits (ahead, behind) are the whole repository’s.

string | null = ...

The branch’s configured upstream, short (origin/main); null when none is set.

Promise<{ files: object[]; truncated: boolean; }>


readGitFileTexts(runGit, repository, paths): Promise<ChangedFileTexts>

Defined in: packages/core/src/git.ts:1036

One changed file of repository whole (readFileTexts): the old side at the baseline commit — none before the first commit — and the new side if git lists it: tracked, or untracked and not ignored, as readGitChanges lists files.

GitRunner

number = Count

Commits on HEAD that baseline.ref does not have; 0 when there is no ref.

{ commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; } = EnsoGitBaseline

string | null = ...

The baseline commit — the merge-base with ref, or HEAD; null for none.

string | null = ...

The remote-tracking ref, short (origin/feature-x); null for head and none.

"head" | "upstream" | "remote-branch" | "remote-default" | "none" = EnsoGitBaselineRule

number = Count

Commits on baseline.ref that HEAD does not have; 0 when there is no ref.

string | null = ...

The checked-out branch, short; null when HEAD is detached.

{ conflicted: number; staged: number; unstaged: number; untracked: number; } = ...

Files under scope by where their changes sit (git status); one file can be staged and unstaged.

number = Count

number = Count

number = Count

number = Count

string | null = ...

HEAD’s commit; null before the first commit.

"repository" = ...

"merge" | "rebase" | "cherry-pick" | "revert" | "bisect" | null = ...

string = ...

The working tree’s top level (git rev-parse --show-toplevel).

string = ...

Where the cwd sits in the working tree (git rev-parse --show-prefix): '' at the top level, else a /-ended path. changes and the changed files are this directory’s alone; the commits (ahead, behind) are the whole repository’s.

string | null = ...

The branch’s configured upstream, short (origin/main); null when none is set.

ChangedFilePaths

Promise<ChangedFileTexts>


readGitState(runGit, cwd): Promise<{ ahead: number; baseline: { commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; }; behind: number; branch: string | null; changes: { conflicted: number; staged: number; unstaged: number; untracked: number; }; head: string | null; kind: "repository"; operation: "merge" | "rebase" | "cherry-pick" | "revert" | "bisect" | null; root: string; scope: string; upstream: string | null; } | { kind: "not-a-repository"; } | { kind: "unavailable"; reason: string; }>

Defined in: packages/core/src/git.ts:441

The git state of cwd: not-a-repository outside one, unavailable with git’s reason when git could not answer, otherwise the repository with its last-push baseline (git-state.ts).

GitRunner

string

Promise<{ ahead: number; baseline: { commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; }; behind: number; branch: string | null; changes: { conflicted: number; staged: number; unstaged: number; untracked: number; }; head: string | null; kind: "repository"; operation: "merge" | "rebase" | "cherry-pick" | "revert" | "bisect" | null; root: string; scope: string; upstream: string | null; } | { kind: "not-a-repository"; } | { kind: "unavailable"; reason: string; }>


readTreeChanges(runGit, comparison): Promise<{ files: object[]; truncated: boolean; }>

Defined in: packages/core/src/git.ts:788

Every file of comparison’s work tree that differs from its base — through runGit, run from root so every path is the root’s — and every untracked file listUntracked names, each with its patch while the answer has room (MAX_* above). readGitChanges over a repository’s own git; a thread’s copy over its snapshot store (#650, snapshot-store.ts).

GitRunner

TreeComparison

Promise<{ files: object[]; truncated: boolean; }>


runGitIn(environment, args, cwd, place?): Promise<GitResult>

Defined in: packages/core/src/git.ts:201

git in cwd, under environment without its repository-locating variables and with the read-only settings above — or, given a place, with exactly that repository’s three (never an inherited one). Exported as the test seam: a test hands in an environment, never the process’s.

ProcessEnv

readonly string[]

string

GitPlace

Promise<GitResult>


scopePathspec(scope): string

Defined in: packages/core/src/git.ts:481

The files under scope and nothing else: from the top level whatever the cwd (top), and character for character, so a directory named [x] or * is not a pattern (literal). An empty scope is the whole working tree. The one spelling of a path given to git — the snapshot store’s too.

string

string


withoutGitLocalVariables(environment): ProcessEnv

Defined in: packages/core/src/git.ts:177

environment without git’s repository-locating variables — what every git this package runs starts from, so an inherited GIT_DIR (a hook’s shell) never names the repository. The snapshot store sets its own three on top (snapshot-store.ts).

ProcessEnv

ProcessEnv