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.
GitReadError
Section titled “GitReadError”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.
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new GitReadError(
message?):GitReadError
Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080
Parameters
Section titled “Parameters”message?
Section titled “message?”string
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Error.constructor
Constructor
Section titled “Constructor”new GitReadError(
message?,options?):GitReadError
Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080
Parameters
Section titled “Parameters”message?
Section titled “message?”string
options?
Section titled “options?”ErrorOptions
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Error.constructor
Constructor
Section titled “Constructor”new GitReadError(
message?,options?):GitReadError
Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1080
Parameters
Section titled “Parameters”message?
Section titled “message?”string
options?
Section titled “options?”ErrorOptions
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Error.constructor
Properties
Section titled “Properties”
readonlyname:"GitReadError"='GitReadError'
Defined in: packages/core/src/git.ts:287
Overrides
Section titled “Overrides”Error.name
ChangedFilePaths
Section titled “ChangedFilePaths”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.
Properties
Section titled “Properties”oldPath
Section titled “oldPath”
readonlyoldPath:string|null
Defined in: packages/core/src/git.ts:879
readonlypath:string
Defined in: packages/core/src/git.ts:878
ChangedFileTexts
Section titled “ChangedFileTexts”Defined in: packages/core/src/git.ts:887
A changed file’s two sides, each its text or why not.
Properties
Section titled “Properties”newText
Section titled “newText”
readonlynewText: {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
oldText
Section titled “oldText”
readonlyoldText: {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
FileTextPlace
Section titled “FileTextPlace”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.
Properties
Section titled “Properties”
readonlybase:string|null
Defined in: packages/core/src/git.ts:908
listed
Section titled “listed”
readonlylisted: (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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<WorkTreeListing>
readonlyroot:string
Defined in: packages/core/src/git.ts:907
GitBounds
Section titled “GitBounds”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).
Properties
Section titled “Properties”
readonlycwd:string
Defined in: packages/core/src/git.ts:145
readonlyenv:ProcessEnv
Defined in: packages/core/src/git.ts:146
maxBuffer
Section titled “maxBuffer”
readonlymaxBuffer:number
Defined in: packages/core/src/git.ts:148
timeout
Section titled “timeout”
readonlytimeout:number
Defined in: packages/core/src/git.ts:147
GitPlace
Section titled “GitPlace”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).
Properties
Section titled “Properties”gitDirectory
Section titled “gitDirectory”
readonlygitDirectory:string
Defined in: packages/core/src/git.ts:189
readonlyindex:string
Defined in: packages/core/src/git.ts:191
workTree
Section titled “workTree”
readonlyworkTree:string
Defined in: packages/core/src/git.ts:190
GitResult
Section titled “GitResult”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.
Properties
Section titled “Properties”
readonlycode:number
Defined in: packages/core/src/git.ts:73
stderr
Section titled “stderr”
readonlystderr:string
Defined in: packages/core/src/git.ts:75
stdout
Section titled “stdout”
readonlystdout:string
Defined in: packages/core/src/git.ts:74
TreeComparison
Section titled “TreeComparison”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.
Properties
Section titled “Properties”
readonlybase:string
Defined in: packages/core/src/git.ts:772
listUntracked
Section titled “listUntracked”
readonlylistUntracked: () =>Promise<readonlystring[]>
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.
Returns
Section titled “Returns”Promise<readonly string[]>
readonlyroot:string
Defined in: packages/core/src/git.ts:770
readonlyscope:string
Defined in: packages/core/src/git.ts:771
GitRunner
Section titled “GitRunner”GitRunner = (
args,cwd) =>Promise<GitResult>
Defined in: packages/core/src/git.ts:83
Runs git with args in cwd — the seam a test replaces.
Parameters
Section titled “Parameters”readonly string[]
string
Returns
Section titled “Returns”Promise<GitResult>
WorkTreeListing
Section titled “WorkTreeListing”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.
GIT_TIMEOUT_MS
Section titled “GIT_TIMEOUT_MS”
constGIT_TIMEOUT_MS:5000=5000
Defined in: packages/core/src/git.ts:58
How long one git query may take.
runGit
Section titled “runGit”
construnGit: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.
UNTRACKED_DIFF_CONCURRENCY
Section titled “UNTRACKED_DIFF_CONCURRENCY”
constUNTRACKED_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()
Section titled “execGit()”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).
Parameters
Section titled “Parameters”readonly string[]
bounds
Section titled “bounds”Returns
Section titled “Returns”object
readonlychild:ChildProcess
result
Section titled “result”
readonlyresult:Promise<GitResult>
gitChildEnvironment()
Section titled “gitChildEnvironment()”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.
Returns
Section titled “Returns”ProcessEnv
isPathInScope()
Section titled “isPathInScope()”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.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”boolean
readCommitChanges()
Section titled “readCommitChanges()”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.
Parameters
Section titled “Parameters”runGit
Section titled “runGit”string
string
string
Returns
Section titled “Returns”Promise<{ files: object[]; truncated: boolean; }>
readCommitFileTexts()
Section titled “readCommitFileTexts()”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).
Parameters
Section titled “Parameters”runGit
Section titled “runGit”string
string
string
Returns
Section titled “Returns”Promise<ChangedFileTexts>
readFileTexts()
Section titled “readFileTexts()”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.
Parameters
Section titled “Parameters”runGit
Section titled “runGit”Returns
Section titled “Returns”Promise<ChangedFileTexts>
readGitChanges()
Section titled “readGitChanges()”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.
Parameters
Section titled “Parameters”runGit
Section titled “runGit”repository
Section titled “repository”number = Count
Commits on HEAD that baseline.ref does not have; 0 when there is no ref.
baseline
Section titled “baseline”{ commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; } = EnsoGitBaseline
baseline.commit
Section titled “baseline.commit”string | null = ...
The baseline commit — the merge-base with ref, or HEAD; null for none.
baseline.ref
Section titled “baseline.ref”string | null = ...
The remote-tracking ref, short (origin/feature-x); null for head and none.
baseline.rule
Section titled “baseline.rule”"head" | "upstream" | "remote-branch" | "remote-default" | "none" = EnsoGitBaselineRule
behind
Section titled “behind”number = Count
Commits on baseline.ref that HEAD does not have; 0 when there is no ref.
branch
Section titled “branch”string | null = ...
The checked-out branch, short; null when HEAD is detached.
changes
Section titled “changes”{ 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.
changes.conflicted
Section titled “changes.conflicted”number = Count
changes.staged
Section titled “changes.staged”number = Count
changes.unstaged
Section titled “changes.unstaged”number = Count
changes.untracked
Section titled “changes.untracked”number = Count
string | null = ...
HEAD’s commit; null before the first commit.
"repository" = ...
operation
Section titled “operation”"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.
upstream
Section titled “upstream”string | null = ...
The branch’s configured upstream, short (origin/main); null when none is set.
Returns
Section titled “Returns”Promise<{ files: object[]; truncated: boolean; }>
readGitFileTexts()
Section titled “readGitFileTexts()”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.
Parameters
Section titled “Parameters”runGit
Section titled “runGit”repository
Section titled “repository”number = Count
Commits on HEAD that baseline.ref does not have; 0 when there is no ref.
baseline
Section titled “baseline”{ commit: string | null; ref: string | null; rule: "head" | "upstream" | "remote-branch" | "remote-default" | "none"; } = EnsoGitBaseline
baseline.commit
Section titled “baseline.commit”string | null = ...
The baseline commit — the merge-base with ref, or HEAD; null for none.
baseline.ref
Section titled “baseline.ref”string | null = ...
The remote-tracking ref, short (origin/feature-x); null for head and none.
baseline.rule
Section titled “baseline.rule”"head" | "upstream" | "remote-branch" | "remote-default" | "none" = EnsoGitBaselineRule
behind
Section titled “behind”number = Count
Commits on baseline.ref that HEAD does not have; 0 when there is no ref.
branch
Section titled “branch”string | null = ...
The checked-out branch, short; null when HEAD is detached.
changes
Section titled “changes”{ 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.
changes.conflicted
Section titled “changes.conflicted”number = Count
changes.staged
Section titled “changes.staged”number = Count
changes.unstaged
Section titled “changes.unstaged”number = Count
changes.untracked
Section titled “changes.untracked”number = Count
string | null = ...
HEAD’s commit; null before the first commit.
"repository" = ...
operation
Section titled “operation”"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.
upstream
Section titled “upstream”string | null = ...
The branch’s configured upstream, short (origin/main); null when none is set.
Returns
Section titled “Returns”Promise<ChangedFileTexts>
readGitState()
Section titled “readGitState()”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).
Parameters
Section titled “Parameters”runGit
Section titled “runGit”string
Returns
Section titled “Returns”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()
Section titled “readTreeChanges()”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).
Parameters
Section titled “Parameters”runGit
Section titled “runGit”comparison
Section titled “comparison”Returns
Section titled “Returns”Promise<{ files: object[]; truncated: boolean; }>
runGitIn()
Section titled “runGitIn()”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.
Parameters
Section titled “Parameters”environment
Section titled “environment”ProcessEnv
readonly string[]
string
place?
Section titled “place?”Returns
Section titled “Returns”Promise<GitResult>
scopePathspec()
Section titled “scopePathspec()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
withoutGitLocalVariables()
Section titled “withoutGitLocalVariables()”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).
Parameters
Section titled “Parameters”environment
Section titled “environment”ProcessEnv
Returns
Section titled “Returns”ProcessEnv
