Skip to main content

Module git

Module git 

Source
Expand description

The git half of an agent’s work facts: repository, branch and uncommitted files in its working folder.

git never runs on a request: a background loop probes each agent’s folder and the request reads the cache. An entry is re-probed once it is REFRESH_AFTER_MS old or the agent’s folder changed. Distinct folders are probed concurrently ([MAX_CONCURRENT_PROBES] at a time) and a probe is abandoned after [PROBE_TIMEOUT], so with a handful of folders an entry is under ~30 s old; many slow repositories can make it older, which is why every answer carries git_checked_ms. Every git run goes through fs_ops::git’s safe runner (the repository’s own fsmonitor and filters are off, nothing prompts, the index isn’t written, a slow run is killed after a few seconds). For a folder a container agent can write, that runner runs git inside the agent’s container and never on the host, so a container agent’s facts are its own git’s.

Structs§

GitCache
Probe results per block id, with the folder each was taken in.
GitFacts
What git says about one working folder.

Constants§

REFRESH_AFTER_MS
An entry this old is probed again on the next tick.

Functions§

branch_contained_in_default
Whether every commit of branch is already in the default branch of root (origin/HEAD, origin/main, origin/master): a merged or fast-forwarded branch. False when either can’t be found. A squash merge leaves the tip outside the default branch: landed_files sees those.
branch_deleted_files
The files that PR deletes (the --diff-filter=D part of branch_files). A release PR deletes every changeset it consumes.
branch_files
The files a PR from head into base changes in root: git diff --name-only base...head, the base being origin/<base> (or a local <base>), else the default branch (origin/HEAD, origin/main, origin/master), and the head a local branch, else origin/<head>. Empty when either can’t be found, on the base itself, or when git can’t say in [PROBE_TIMEOUT]. A diff of two commits: no working-tree filter runs.
cached
The cached facts for block in dir (see GitCache::get).
landed_files
Of files (which their_branch changes in their_root), the ones whose content on that branch is exactly what the PR’s base has in my_root: the change already landed there (a squash merge leaves the branch tip outside the base, but the blobs are the same), so it is no overlap. Blob ids are content hashes, comparable across clones. A file either side can’t be read is kept.
merge_base_setting
The branch’s gh-merge-base setting (gh’s base for a PR from it), if set.
probe
Probe dir: None when it isn’t inside a git repository (or git is missing or too slow).
refresh_once
One refresh pass: probe each due (block, folder) in folders, every distinct folder once and at most [MAX_CONCURRENT_PROBES] at a time, each abandoned after timeout, and store the results stamped now_ms.
run_git_refresh_loop
Keep every registered agent’s git facts fresh. Never returns.