Skip to main content

chant/repository/
git_repository.rs

1use anyhow::Result;
2
3/// A trait for git repository operations.
4pub trait GitRepository {
5    /// Get the current branch name.
6    fn get_current_branch(&self) -> Result<String>;
7
8    /// Check if a branch exists.
9    fn branch_exists(&self, name: &str) -> Result<bool>;
10}
11
12/// Command-based implementation of GitRepository.
13pub struct CommandGitRepository;
14
15impl CommandGitRepository {
16    /// Create a new CommandGitRepository.
17    pub fn new() -> Self {
18        Self
19    }
20}
21
22impl Default for CommandGitRepository {
23    fn default() -> Self {
24        Self::new()
25    }
26}
27
28impl GitRepository for CommandGitRepository {
29    fn get_current_branch(&self) -> Result<String> {
30        crate::git::get_current_branch()
31    }
32
33    fn branch_exists(&self, name: &str) -> Result<bool> {
34        crate::git::branch_exists(name)
35    }
36}