Skip to main content

Module git

Module git 

Source
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§

BatchedTouchMetrics
Batched touch metrics for all files in a repository.
CoChangePair
A pair of files that frequently change together in the same commit
FileChurn
File churn metrics (lines added/deleted)
GitContext
Git context for the current commit
PrContext
PR context information
TempWorktree
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 log calls (up to 500 files per invocation). This replaces O(N) individual git log -1 -- file calls 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 sha and 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 file at or before before_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_days days.
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.