repotoire 0.9.0

Graph-powered code analysis CLI. 110 detectors for security, architecture, bus factor, and code quality.
Documentation
pub mod blame;
pub mod commit;
pub mod deflate;
pub mod diff;
pub mod error;
pub mod merge_base;
pub mod object;
pub mod oid;
pub mod pack;
pub mod pack_index;
pub mod repo;
pub mod revwalk;
pub mod sha1;
pub mod tree;

pub use blame::{blame_file, BlameHunk};
pub use commit::RawCommit;
pub use diff::{
    compute_stats, diff_blobs, diff_trees, diff_trees_with_stats, DiffDelta, DiffHunk, DiffStats,
    DiffStatus,
};
pub use error::GitError;
pub use object::ObjectType;
pub use oid::Oid;
pub use repo::RawRepo;
pub use revwalk::RevWalk;
pub use tree::{parse_tree, TreeEntry};

/// Shared test helpers for all raw git submodules.
#[cfg(test)]
pub(crate) mod tests {
    use std::path::PathBuf;

    /// Resolve the repository's *common* git directory (where `objects/pack/` lives).
    ///
    /// Uses `git rev-parse --git-common-dir` rather than walking up for a `.git/` directory,
    /// so it works both from a normal checkout and from a linked `git worktree` — where
    /// `.git` is a *file* (`gitdir:` pointer to `<main-repo>/.git/worktrees/<name>`), not a
    /// directory, but `--git-common-dir` still resolves to `<main-repo>/.git/`.
    pub fn find_repo_git_dir() -> PathBuf {
        let manifest = env!("CARGO_MANIFEST_DIR");
        let out = std::process::Command::new("git")
            .args(["-C", manifest, "rev-parse", "--git-common-dir"])
            .output()
            .expect("failed to run `git rev-parse --git-common-dir`");
        assert!(
            out.status.success(),
            "not in a git repo (`git rev-parse --git-common-dir` failed): {}",
            String::from_utf8_lossy(&out.stderr)
        );
        let raw = String::from_utf8_lossy(&out.stdout);
        let raw = raw.trim();
        assert!(
            !raw.is_empty(),
            "`git rev-parse --git-common-dir` returned empty output"
        );
        let p = PathBuf::from(raw);
        // git prints the path relative to `manifest` (we passed `-C manifest`) unless absolute.
        if p.is_absolute() {
            p
        } else {
            PathBuf::from(manifest).join(p)
        }
    }
}