Expand description
Git context extraction
Extracts git metadata for the current commit deterministically.
Global invariants enforced:
- Commit hash is the sole identity
- Branch names are metadata only
- Missing parents produce baselines, not errors
Uses git CLI directly (no libgit2) for portability.
Structs§
- Batched
Touch Metrics - Batched touch metrics for all files in a repository.
- CoChange
Pair - A pair of files that frequently change together in the same commit
- File
Churn - File churn metrics (lines added/deleted)
- GitContext
- Git context for the current commit
- PrContext
- PR context information
- Temp
Worktree - A temporary git worktree that is removed when dropped.
Functions§
- batch_
last_ touch_ for_ files - For files absent from the 30-day window, find the most recent commit timestamp
for each using batched
git logcalls (up to 500 files per invocation). This replaces O(N) individualgit log -1 -- filecalls with O(N/500) calls. - batch_
touch_ metrics_ at - Compute touch metrics for all files in a repository using two git log calls.
- count_
file_ touches_ 30d - Count how many commits touched a file in the last 30 days
- count_
file_ touches_ 30d_ at - Count file touches at a specific repository path
- create_
worktree - Create a temporary detached worktree at
shaand return a drop guard. - days_
since_ last_ change - Calculate days since last change to a file
- days_
since_ last_ change_ at - Calculate days since last change at a specific repository path
- days_
since_ last_ change_ at_ sha - Days since the last change to
fileat or beforebefore_sha. Returns None if the file has no history before that SHA. - detect_
fix_ commit - Detect if a commit message indicates a fix/bug fix
- detect_
pr_ context - Detect if we’re in a PR context via CI environment variables
- detect_
revert_ commit - Detect if a commit is a revert
- extract_
co_ change_ pairs - Mine co-change pairs from git log over the last
window_daysdays. - extract_
commit_ churn - Extract commit churn (lines added/deleted per file)
- extract_
commit_ churn_ at - Extract commit churn at a specific repository path
- extract_
git_ context - Extract git context for the current commit
- extract_
git_ context_ at - Extract git context for a specific repository path
- extract_
ticket_ ids - Extract ticket IDs from commit message and branch name
- find_
merge_ base - Find the merge-base SHA and Unix timestamp between HEAD and main/master. Returns None when already on main (merge-base == HEAD) or no divergence found.
- function_
touch_ metrics_ at - Per-function touch metrics using
git log -L start,end:file. - resolve_
merge_ base - Resolve merge-base between current HEAD and target branch
- resolve_
merge_ base_ auto - Resolve merge-base with common target branches
- resolve_
ref_ to_ sha - Resolve a git ref (branch, tag, SHA, HEAD~N, etc.) to a full 40-character SHA.