pub async fn current_branch(cwd: &Path) -> Result<Option<String>, RepoGate>Expand description
Run the full scan sequence against cwd and return a snapshot.
Always succeeds - every failure path collapses to a non-InRepo
repo_gate and a log line naming the step that failed. Callers
should treat the snapshot as authoritative for rendering
regardless of which variant came back.
prev is the most recent snapshot for this cwd (if any). It’s
used to reuse cached PR info while the branch name, pushed sha
and fetch age (5 minutes) all say the cached answer still holds
(pr_cache_fresh). Pass None for cold starts.
The caller’s current branch name via git rev-parse --abbrev-ref HEAD,
keeping a detached HEAD apart from a failed read: Ok(Some(name)) on
a named branch, Ok(None) on a detached HEAD, Err(gate) when git
reported nothing usable. Mirrors the GitBranch::Named string
scan derives, so the review MCP can resolve a caller’s (project, branch) review scope to the same key the /diff overlay persists
under - and name the step that failed when it can’t.