cascade_cli/git/
mod.rs

1pub mod branch_manager;
2pub mod repository;
3
4pub use branch_manager::{BranchInfo, BranchManager};
5pub use repository::{GitRepository, RepositoryInfo};
6
7use crate::errors::{CascadeError, Result};
8use std::path::Path;
9
10/// Check if a directory is a Git repository
11pub fn is_git_repository(path: &Path) -> bool {
12    path.join(".git").exists() || git2::Repository::discover(path).is_ok()
13}
14
15/// Find the root of the Git repository
16pub fn find_repository_root(start_path: &Path) -> Result<std::path::PathBuf> {
17    let repo = git2::Repository::discover(start_path).map_err(CascadeError::Git)?;
18
19    let workdir = repo
20        .workdir()
21        .ok_or_else(|| CascadeError::config("Repository has no working directory (bare repo?)"))?;
22
23    Ok(workdir.to_path_buf())
24}
25
26/// Get the current working directory as a Git repository
27pub fn get_current_repository() -> Result<GitRepository> {
28    let current_dir = std::env::current_dir()
29        .map_err(|e| CascadeError::config(format!("Could not get current directory: {e}")))?;
30
31    GitRepository::open(&current_dir)
32}