Skip to main content

Module git

Module git 

Source

Re-exports§

pub use worktree::Worktree;

Modules§

worktree
git worktree wrapper for hermetic per-run workspaces.

Structs§

AtomicPushSpec
Inputs to push_branch_and_tags_atomic_in.
Commit
CommitWithFiles
A commit paired with the workspace-relative paths it touched.
CommitterIdentity
Committer identity (author + committer name/email) for the rare path where a git invocation lands on a host with no user.email / user.name configured — notably actions/checkout@v6, which does NOT set committer identity for the workflow runner. Resolved once per caller and threaded through to revert_commit_in so the CLI never mutates the repo’s git config (env-only, scoped to the single spawn).
GitInfo
GithubRepoProbe
One GitHub repo push-probe: the coordinates, the credential, the retry budget (attempt ladder plus the invocation’s wall-clock deadline) the probe must stay inside, and the strictness the outcome is graded under.
RepoAccessOutcomes
The two outcomes whose severity + wording genuinely differ between the preflight callers of github_repo_push_check: an unwritable repo blocks the required github-release target but only warns for a tap/index repo, and the missing/denied wording names what the caller was probing.
RepoSlug
A validated repository identity: owner (user/org, or a GitLab nested group/subgroup path) plus the repository name.
SemVer

Enums§

ConventionalLevel
Release level implied by a single Conventional-Commits message.
RepoProbe
Terminal classification of a single GET /repos/{owner}/{repo} probe, carrying enough to distinguish a transient rate-limit 403 from an auth 403.
TagPosition
Where a tag’s ref sits relative to the current HEAD.
TagSource
How the tag carried by a GitInfo was arrived at.

Constants§

CHANGELOG_PROVENANCE_PREFIX
Prefix of the changelog-provenance marker lines the tag and bump --commit commands record in the version-bump commit body when their --changelog refresh regenerates on-disk CHANGELOG.md files.
GITHUB_TOKEN_ENV_LADDER
The ordered env-var ladder consulted (after any explicit CLI/context value) when resolving a GitHub token: ANODIZER_GITHUB_TOKEN is preferred, then GITHUB_TOKEN, then GH_TOKEN (the gh CLI’s conventional var, so runners configured only for gh still authenticate). This is the single source of truth for the ladder — resolve_github_token_with_env (the only real reader) consumes it, and the config-aware preflight builds its EnvAnyOf lists from it so the validated set cannot drift from the set the resolver actually reads.
RELEASE_COMMIT_PREFIX
Subject prefix anodizer stamps on its own release-machinery commits (version-sync bumps, rollback reverts). The matchers that must recognise those commits — rollback’s idempotency check, the changelog stage’s version-sync exclusion — compose their patterns from this same constant so a reworded writer can never silently break a matcher.
SHORT_COMMIT_LEN
Default short-commit length used across error messages, log output, and any place that needs to truncate a full SHA for human display. Matches git’s --short default (7) — and the ShortCommit template var populated by crate::git::detect_git_info (which delegates to git rev-parse --short).

Functions§

add_path_in
git -C <workspace_root> add <rel> — stage a single relative path.
branches_containing_sha_in
Return remote branch short names that contain sha (e.g. master, release/v1). The bump commit’s SHA is the deterministic anchor of the tag, so deriving the push branch from it is race-immune to the default branch moving between bump and rollback. Empty Vec when the SHA is not on any remote branch (orphan / not-yet-pushed).
canonical_author_email_in
Canonicalize an author identity to its .mailmap email in cwd’s repo.
changelog_regenerated_marker
Marker line recording that the tool regenerated the changelog file owned by crate_name at version: changelog regenerated for <crate>@<version>. Always crate-scoped, so one crate’s regeneration can never vouch for a same-numbered version of a different crate, and a root-only aggregate that touched no packaged crate’s own CHANGELOG.md mints no marker at all.
changelog_regenerated_recorded_in
Whether the LAST commit that touched changelog_rel_path (repo-relative, /-separated) in workspace_root records that the tool regenerated the changelog for crate_name at version.
check_git_available
Check whether git is available in PATH.
classify_commit
Classify one commit message (subject + body) against the Conventional-Commits release rules.
commit_author_login
Resolve a commit author’s GitHub login from a representative commit SHA via GET /repos/{owner}/{repo}/commits/{sha}.author.login.
commit_author_login_with_binary
Path-taking sibling of commit_author_login so tests can point at a missing or stub binary without mutating PATH.
commit_in
git -C <workspace_root> commit [-S] -m <message> — create a commit with the given message, optionally GPG-signed.
commit_subject_in
git log -1 --format=%s <sha> — return the subject line of a single commit. Used to render the “non-bump commit subject” list when the rollback safety check fires.
commits_between_in
git rev-list <sha>..HEAD — list the commit hashes (newest-first) that sit on top of sha but aren’t in sha.
commits_with_subjects_in
git log --format=%H%x1f%s <sha>..HEAD — return every (full_sha, subject) pair in the range in one subprocess. Used by the rollback safety check so classifying N intervening commits is a single git spawn rather than 1 + N (one rev-list plus one log -1 per commit).
count_commits_since_last_tag_in
Count the commits on HEAD since the most recent reachable tag.
create_and_push_tag
Create an annotated tag and push it if an origin remote exists.
create_and_push_tag_in
Create an annotated tag in cwd and push it if an origin remote exists.
create_tag_local_only
Create an annotated tag locally without pushing.
create_tag_via_github_api
Create a tag via the GitHub API (using the gh CLI).
create_tag_via_github_api_in
Path-taking sibling of create_tag_via_github_api.
delete_local_tag_in
Delete a local tag (git tag -d <tag>). Returns Ok(()) even when the tag is missing so callers can run the delete idempotently.
delete_remote_tag_in
Delete a tag on the origin remote (git push origin :refs/tags/<tag>).
detect_git_info
Detect git info for a given tag.
detect_git_info_in
Detect git info for a given tag against a repository at cwd.
detect_remote_web_base_in
Get the web base (https://host/owner/repo) for the origin remote configured in cwd, regardless of SCM host.
extract_tag_prefix
Extract the prefix portion of a tag template by locating the version placeholder.
filter_ignored_tags
Filter an arbitrary tag list through the user’s ignore_tags (glob) / ignore_tag_prefixes (starts-with) config plus the unconditional is_nightly_tag exclusion — the same semantics find_latest_tag_matching_in applies to its candidate set, packaged for callers that obtain tags elsewhere (e.g. tags-at-HEAD crate selection). Ignore patterns are template-rendered when vars is provided.
find_latest_tag_matching
Find the latest tag matching a template pattern. E.g., tag_template “cfgd-core-v{{ .Version }}” → matches tags like “cfgd-core-v1.2.3”
find_latest_tag_matching_in
Path-taking sibling of find_latest_tag_matching.
find_latest_tag_matching_with_prefix
Like find_latest_tag_matching, but with optional monorepo prefix filtering.
find_latest_tag_matching_with_prefix_in
Path-taking sibling of find_latest_tag_matching_with_prefix.
find_previous_tag
Find the tag immediately before current_tag in commit history.
find_previous_tag_in
Path-taking sibling of find_previous_tag.
find_previous_tag_in_family
Find the tag preceding current_tag inside the tag family that tag_template mints.
find_previous_tag_in_family_in
Path-taking sibling of find_previous_tag_in_family.
find_previous_tag_with_prefix
Like find_previous_tag, but with optional monorepo prefix filtering.
find_previous_tag_with_prefix_in
Path-taking sibling of find_previous_tag_with_prefix.
get_all_commits
Get all commits reachable from HEAD, optionally filtered to a path. Used for initial releases where there is no previous tag.
get_all_commits_in
Path-taking sibling of get_all_commits.
get_all_commits_paths
Get all commits reachable from HEAD, filtered to multiple paths.
get_all_commits_paths_in
Path-taking sibling of get_all_commits_paths.
get_all_commits_paths_with_files_in
--name-only sibling of get_all_commits_paths_in.
get_all_semver_tags
Get all semver tags in the repo, sorted descending by version. Prerelease tags sort after release tags of the same major.minor.patch.
get_all_semver_tags_in
Path-taking sibling of get_all_semver_tags.
get_branch_semver_tags
Get semver tags reachable from HEAD, sorted descending by version. Prerelease tags sort after release tags of the same major.minor.patch.
get_branch_semver_tags_in
Path-taking sibling of get_branch_semver_tags.
get_commit_messages_between
Get commit subjects between two refs.
get_commit_messages_between_in
Path-taking sibling of get_commit_messages_between.
get_commit_messages_between_path
Get commit subjects between two refs that touched a specific path.
get_commit_messages_between_path_in
Path-taking sibling of get_commit_messages_between_path.
get_commits_between
Get commits between two refs, optionally filtered to a path.
get_commits_between_in
Path-taking sibling of get_commits_between.
get_commits_between_paths
Get commits between two refs, filtered to multiple paths (git log – path1 path2 …).
get_commits_between_paths_in
Path-taking sibling of get_commits_between_paths.
get_commits_between_paths_with_files_in
--name-only sibling of get_commits_between_paths_in: each commit is paired with the repo-relative paths it touched, for a precise changelog.paths glob intersect over the git-pathspec scope.
get_commits_reachable_paths_in
All commits reachable from an arbitrary rev (not just HEAD), filtered to paths. Used by the changelog stage to bound a no-lower-bound range at an explicit upper ref (changelog ..<tag>): the range is then every ancestor of <tag>, excluding commits made after it.
get_commits_reachable_paths_with_files_in
--name-only sibling of get_commits_reachable_paths_in.
get_current_branch
Get the current branch name.
get_current_branch_in
Path-taking sibling of get_current_branch.
get_current_branch_in_with_env
EnvSource-injecting form of get_current_branch_in.
get_first_commit
Return the SHA of the very first commit in the repository.
get_first_commit_in
Path-taking sibling of get_first_commit.
get_head_commit
Get the full commit hash of HEAD.
get_head_commit_in
Path-taking sibling of get_head_commit.
get_last_commit_messages
Get last N commit subjects.
get_last_commit_messages_in
Path-taking sibling of get_last_commit_messages.
get_last_commit_messages_path
Get last N commit subjects that touched a specific path.
get_last_commit_messages_path_in
Path-taking sibling of get_last_commit_messages_path.
get_short_commit
Get the short commit hash of HEAD.
get_short_commit_in
Path-taking sibling of get_short_commit.
get_tags_at_head
Return all tags that point at the current HEAD commit.
get_tags_at_head_in
Path-taking sibling of get_tags_at_head.
get_tags_at_sha_in
Return all tags that point at the given commit (any revision spec).
gh_api_delete_with_binary
DELETE a GitHub API endpoint via gh_binary.
gh_api_get
GET a GitHub API endpoint via the gh CLI (single request, no pagination).
gh_api_get_paginated
GET a GitHub API endpoint via the gh CLI, with pagination.
gh_api_get_paginated_with_binary
Paginated GET via gh_binary. Path-taking sibling of gh_api_get_paginated.
gh_api_get_with_binary
GET a GitHub API endpoint via gh_binary (single request, no pagination).
gh_api_get_with_binary_with_env
Env-injectable sibling of gh_api_get_with_binary, mirroring the resolve_github_token/resolve_github_token_with_env split: env stands in for std::env::vars() when redacting the bailed error message, so a test asserting on the raw gh stderr text does not depend on the real ambient process environment (which may contain secret-suffixed values that happen to collide with the asserted substring).
git_status_porcelain
Return the git status --porcelain output showing dirty files.
git_status_porcelain_in
Return the git status --porcelain output from a repository at cwd.
git_status_porcelain_result_in
Return the git status --porcelain output from a repository at cwd, surfacing the underlying git failure instead of swallowing it.
github_repo_probe
Run the GET /repos/{owner}/{repo} request under the shallow probe policy, reading response headers (not just the status) so a secondary-rate-limit 403 is separable from an auth 403. 5xx and retriable transport errors retry within policy and stop once deadline — the invocation’s wall-clock budget — is spent; everything else resolves on the first response.
github_repo_push_check
Probe GET {url} and map the outcome onto a PreflightCheck.
github_token_env_hint
The env-var fragment of a “no GitHub token” remediation hint, rendered from GITHUB_TOKEN_ENV_LADDER in actual resolution-precedence order: ANODIZER_GITHUB_TOKEN or GITHUB_TOKEN or GH_TOKEN. Error messages interpolate this (or github_token_hint) instead of restating the vars, so a hand-spelled hint can never list the ladder in the wrong order or go stale when a var is added or renamed.
github_token_hint
Full remediation hint for surfaces that also accept a --token flag: set ANODIZER_GITHUB_TOKEN or GITHUB_TOKEN or GH_TOKEN, or pass --token, rendered from GITHUB_TOKEN_ENV_LADDER.
has_changes_since
Check if there are changes in a path since a given tag.
has_changes_since_in
Path-taking sibling of has_changes_since.
has_commits_since_tag
Check if there are any commits since a given tag.
has_commits_since_tag_in
Path-taking sibling of has_commits_since_tag.
has_remote_in
Whether remote (e.g. "origin") is configured in the git repo at cwd.
has_version_placeholder
Check whether a tag template string contains any recognised version placeholder.
head_commit_hash_in
Return HEAD’s full commit hash for the given repository (or worktree).
head_commit_timestamp_in
git -C <repo> log -1 --format=%ct HEAD — return HEAD’s committer timestamp (seconds since UNIX epoch) for the given repository. Used by the determinism harness as the non-snapshot SDE seed.
head_is_at_tag
Returns true when HEAD coincides with a tag.
indeterminate_check
Wrap an indeterminate probe outcome (the probe could not reach a verdict) in its effective severity: Warning by default so a transient upstream blip cannot abort an otherwise-valid release, Blocker under strict preflight (fail-closed).
is_branchlike
Return true when name looks like a branch (NOT an anodize-shaped release tag). Tag shapes: ^v\d+\.\d+\.\d+ (lockstep v1.2.3[-pre][+build]) or ^<crate>-v\d+\.\d+\.\d+ (per-crate mycrate-v1.2.3[...]).
is_git_dirty
Check whether the working tree has uncommitted changes.
is_git_dirty_in
Check whether the working tree in cwd has uncommitted changes.
is_git_repo
Check whether the current directory is inside a git repository.
is_git_repo_in
Check whether cwd is inside a git repository.
is_nightly_tag
Whether tag carries anodizer’s own nightly marker: the literal tag nightly (the default nightly.tag_name), or a nightly token delimited by - / . / + inside the version portion — the shape every supported nightly.version_template produces (default …-{{ ShortCommit }}-nightly, nushell-style …-nightly.{{ NightlyBuild }}+…).
is_rate_limit_signature
Whether an error body marks the response as rate-limited at all (primary quota exhaustion or a secondary limit): any 429, or a 403 whose message / documentation_url carries a rate-limit signal.
is_secondary_rate_limit_signature
Whether an error body matches GitHub’s secondary rate-limit signature: a 403 / 429 whose message mentions “secondary rate limit” (case-insensitive) or whose documentation_url points at secondary-rate-limits.
is_shallow_clone
Check whether the current repository is a shallow clone.
is_shallow_clone_in
Check whether the repository at cwd is a shallow clone.
list_remote_tag_names_in
List tag names on remote via a single git ls-remote --tags call.
list_tags_with_prefix
git -C <workspace_root> tag --list --sort=-v:refname '<prefix>*' — return the list of refs whose name starts with prefix, ordered by reverse semver. Returns Ok(Vec::new()) when git fails (no repo, no tags) so callers can treat absence as a non-error.
list_tracked_files_in
List the repository’s tracked files (git ls-files) as repo-relative paths.
local_git_user_email
Read git config user.email, or None if unset / git is unavailable.
local_git_user_email_in
Read git config user.email from a repository at cwd.
local_git_user_name
Read git config user.name, or None if unset / git is unavailable.
local_git_user_name_in
Read git config user.name from a repository at cwd.
log_subjects_for_range
git -C <workspace_root> -c log.showSignature=false log --pretty=format:%B%x1e <range> -- <rel_path> — list commit message bodies (subject+body) for commits in range touching rel_path, using the \x1e (RS) byte as a between-commits separator so multi-line bodies survive parsing.
parse_commit_output
Parse git log output (formatted as %H%x1f%h%x1f%s%x1f%an%x1f%ae%x1f%b%x1e) into a vec of Commits.
parse_commit_output_with_files
Parse git log --name-only output (metadata formatted as %H%x1f...%b%x1e, followed by one touched-file path per line) into CommitWithFiles.
parse_remote_web_base
Convert a git remote URL into its web base (https://host/owner/repo), regardless of SCM host.
parse_semver
Parse a strict semver version from a string like “v1.2.3”, “1.2.3”, “v1.0.0-rc.1”, “v1.0.0+build.42”, or “v1.0.0-rc.1+build.42”.
parse_semver_tag
paths_changed_since_tag
git diff --name-only <tag>..HEAD -- <paths>... — return true when any of the named paths changed between tag and HEAD. Returns Ok(false) when git fails (e.g. not a git repo) so callers can treat the absence-of-info case as “no changes”.
paths_changed_since_tag_in
Path-taking sibling of paths_changed_since_tag.
per_crate_tag_prefix
The tag-family prefix used for a crate: the prefix extracted from its tag_template, falling back to the <name>-v convention when the template is empty or carries no recognised version placeholder.
probe_to_push_check
Pure probe→check mapper backing github_repo_push_check, split out so the classification arms are unit-testable without an HTTP responder.
push_branch_and_tags_atomic_in
Push an optional branch and all tags to a remote atomically.
push_branch_in
Push a branch (HEAD:refs/heads/<branch>) to the origin remote.
release_bump_subject
Build a version-sync bump commit subject: chore(release): bump <summary><suffix>. suffix carries the optional [skip ci] marker (empty when none applies).
release_bump_subject_prefix
chore(release): bump — the subject prefix shared by every version-sync bump commit (see release_bump_subject).
render_ignore_patterns
Render ignore patterns (both ignore_tags and ignore_tag_prefixes) through the template engine when template_vars is provided.
reset_hard_in
Run git reset --hard <sha> in cwd. Destructive — rewrites HEAD and the index in place; callers must surface a warning before invoking.
resolve_github_slug
Process-cwd sibling of resolve_github_slug_in.
resolve_github_slug_in
Resolve the GitHub repository identity for the repo at cwd.
resolve_github_token
Process-env wrapper of resolve_github_token_with_env for call sites without a Context (e.g. the bump/tag changelog-sync write path, whose commands expose no --token flag).
resolve_github_token_with_env
Resolve the GitHub token for API calls through the codebase-standard chain: explicit value (CLI flag / context option) → the GITHUB_TOKEN_ENV_LADDER (ANODIZER_GITHUB_TOKENGITHUB_TOKENGH_TOKEN). Empty strings count as absent at every link — GitHub Actions materializes missing secrets as "", which must not short-circuit the fallback to the next link.
resolve_repo_slug
Process-cwd sibling of resolve_repo_slug_in.
resolve_repo_slug_in
Host-agnostic sibling of resolve_github_slug_in (GitHub, GitLab, Gitea, self-hosted).
resolve_rollback_identity
Resolve the committer identity to use for a rollback-style commit. When the host already has user.name AND user.email configured (or GIT_AUTHOR_* / GIT_COMMITTER_* are set in the parent env), returns an empty identity so the child inherits the existing values. Otherwise returns a synthetic identity so the commit doesn’t fail with “Author identity unknown” on bare-CI hosts.
resolve_snapshot_sde
Resolves the SOURCE_DATE_EPOCH for a snapshot-mode release run.
response_is_rate_limited
Whether a GitHub response’s headers mark it as rate-limited: a Retry-After header (primary or secondary limit) or X-RateLimit-Remaining: 0. Header lookups are case-insensitive (reqwest::header::HeaderMap).
rev_parse_in
Resolve a revision (sha, ref name, HEAD, etc.) to its full commit hash.
rev_verify_commit_in
git rev-parse --verify <rev>^{commit} — resolve rev to a commit SHA, erroring when it does not name an existing commit. Stricter than rev_parse_in: --verify rejects ambiguous / non-existent refs (rather than echoing the input back), and the ^{commit} peel rejects a ref that resolves to a non-commit object (e.g. a tree or blob SHA).
revert_commit_in
Run git revert --no-edit <sha> in cwd, optionally followed by git commit --amend -m <message>.
short_commit_str
Truncate a full commit SHA string to SHORT_COMMIT_LEN characters. Returns the input unchanged when it’s already shorter or equal in length. Use this any time the SHA arrives as a string (e.g. deserialized from a manifest or read from a template var) rather than running git rev-parse --short again — saves a subprocess and keeps the length convention in one place.
split_tag_family
Split a release tag into its family prefix and the parsed version it stamps: crd-v0.5.0 → ("crd-v", 0.5.0), v1.2.3 → ("v", 1.2.3), sub/v1.2.3-rc.1 → ("sub/v", 1.2.3-rc.1). Two tags with equal prefixes belong to the same tag family (the same tag_template track). None when no semver version can be located in the tag.
stage_and_commit
Stage specific files and create a commit.
stage_and_commit_in
Path-taking sibling of stage_and_commit.
strip_monorepo_prefix
Strip a monorepo tag prefix from a tag string.
tag_family_glob
The glob describing the tag family tag_template mints — literally the filter find_previous_tag_in_family applies, so a diagnostic quoting it cannot drift from the search that was actually performed. None when nothing scopes the search.
tag_points_at_head
Check whether tag points at the current HEAD commit.
tag_points_at_head_in
Path-taking sibling of tag_points_at_head, with the same missing-tag-is-an-error contract.
tag_position_in
Resolve where tag sits relative to HEAD, in the repository at cwd.
version_from_tag
Parse a semver version from a prefixed tag string.