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
10pub fn is_git_repository(path: &Path) -> bool {
12 path.join(".git").exists() || git2::Repository::discover(path).is_ok()
13}
14
15pub 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
26pub 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 let repo_root = find_repository_root(¤t_dir)?;
32 GitRepository::open(&repo_root)
33}