Skip to main content

anodizer_core/git/
mod.rs

1use anyhow::{Result, bail};
2use std::process::Command;
3
4mod commits;
5mod detect;
6mod github_api;
7mod remote;
8mod semver;
9mod snapshot_sde;
10mod status;
11mod tags;
12pub mod worktree;
13
14#[cfg(test)]
15mod tests;
16
17pub use commits::{
18    Commit, SHORT_COMMIT_LEN, add_path_in, commit_in, get_all_commits, get_all_commits_paths,
19    get_commit_messages_between, get_commit_messages_between_path, get_commits_between,
20    get_commits_between_paths, get_current_branch, get_head_commit, get_last_commit_messages,
21    get_last_commit_messages_path, get_short_commit, has_changes_since, has_commits_since_tag,
22    head_commit_hash_in, head_commit_timestamp_in, log_subjects_for_range, paths_changed_since_tag,
23    short_commit_str, stage_and_commit,
24};
25pub use detect::{GitInfo, detect_git_info};
26pub use github_api::{create_tag_via_github_api, gh_api_get, gh_api_get_paginated};
27pub use remote::{
28    detect_github_repo, detect_owner_repo, parse_github_remote, parse_remote_owner_repo,
29};
30pub use semver::{SemVer, parse_semver, parse_semver_tag};
31pub use snapshot_sde::resolve_snapshot_sde;
32pub use status::{
33    check_git_available, git_status_porcelain, is_git_dirty, is_git_repo, is_shallow_clone,
34    local_git_user_email, local_git_user_name,
35};
36pub use tags::{
37    create_and_push_tag, extract_tag_prefix, find_latest_tag_matching,
38    find_latest_tag_matching_with_prefix, find_previous_tag, find_previous_tag_with_prefix,
39    get_all_semver_tags, get_branch_semver_tags, get_first_commit, has_version_placeholder,
40    head_is_at_tag, list_tags_with_prefix, render_ignore_patterns, strip_monorepo_prefix,
41    tag_points_at_head,
42};
43pub use worktree::Worktree;
44
45/// Run a git command and return stdout, trimmed.
46///
47/// Shared low-level wrapper used by every submodule. Private to the `git`
48/// module — children automatically see private parent items.
49///
50/// On non-zero exit the stderr is passed through
51/// [`crate::redact::redact_process_env`] before interpolation, so any
52/// token-bearing remote URL git might echo (e.g.
53/// `https://ghp_xxx@github.com/...` produced by an `extraHeader` config
54/// leak) is scrubbed in the bail message.
55fn git_output(args: &[&str]) -> Result<String> {
56    let output = Command::new("git").args(args).output()?;
57    if !output.status.success() {
58        let stderr_raw = String::from_utf8_lossy(&output.stderr);
59        let raw = format!("git {} failed: {}", args.join(" "), stderr_raw.trim());
60        bail!("{}", crate::redact::redact_process_env(&raw));
61    }
62    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
63}