Skip to main content

head_sha

Function head_sha 

Source
pub fn head_sha(path: &Path) -> Result<String>
Expand description

Resolve HEAD sha for the repo at path, or empty string if not a repo.

Errors are demoted to empty string so non-git directories index cleanly. We log at debug so operators can distinguish “not a repo” (expected) from “broken refs / unborn HEAD / detached HEAD” (worth investigating) when a repo unexpectedly has no recency weighting.

§M4: open not discover

Uses Repository::open instead of Repository::discover so that only the exact directory path is opened as a git repo. discover walks parent directories: calling it on a subdirectory of a repo returns the repo root, so the recency weighting would silently apply to a different (larger) scope. open returns an error for non-root paths, which we demote to empty-string as for non-repos.

§L8: Result<String> is retained

The function currently always returns Ok(…) — errors are demoted to Ok(String::new()). The Result wrapper is kept for two reasons: (a) callers already propagate it with ?, changing the return type is a silent breaking change; (b) a future version may propagate IO errors (e.g. permission denied reading .git/HEAD) to let callers decide the error policy.