Skip to main content

omni_dev/git/
mod.rs

1//! Git operations and repository management
2
3use anyhow::{Context, Result};
4use git2::Repository;
5
6pub mod amendment;
7pub mod commit;
8pub mod remote;
9pub mod repository;
10
11pub use amendment::AmendmentHandler;
12pub use commit::{CommitAnalysis, CommitAnalysisForAI, CommitInfo, CommitInfoForAI};
13pub use remote::RemoteInfo;
14pub use repository::GitRepository;
15
16/// Check if the current directory is a git repository
17pub fn check_git_repo() -> Result<()> {
18    Repository::open(".").context("Not in a git repository")?;
19    Ok(())
20}
21
22/// Check if working directory is clean
23pub fn check_working_directory_clean() -> Result<()> {
24    let repo = Repository::open(".").context("Failed to open git repository")?;
25
26    let statuses = repo
27        .statuses(None)
28        .context("Failed to get repository status")?;
29
30    if !statuses.is_empty() {
31        anyhow::bail!(
32            "Working directory is not clean. Please commit or stash changes before amending commit messages."
33        );
34    }
35
36    Ok(())
37}