Skip to main content

changeset_operations/traits/
git_provider.rs

1use std::path::Path;
2
3use changeset_git::{CommitInfo, FileChange, TagInfo};
4
5use crate::Result;
6
7pub trait FullGitProvider:
8    GitDiffProvider + GitStatusProvider + GitStagingProvider + GitCommitProvider + GitTagProvider
9{
10}
11impl<
12    T: GitDiffProvider + GitStatusProvider + GitStagingProvider + GitCommitProvider + GitTagProvider,
13> FullGitProvider for T
14{
15}
16
17pub trait GitDiffProvider: Send + Sync {
18    /// # Errors
19    ///
20    /// Propagates repository errors.
21    fn changed_files(&self, project_root: &Path, base: &str, head: &str)
22    -> Result<Vec<FileChange>>;
23}
24
25pub trait GitStatusProvider: Send + Sync {
26    /// # Errors
27    ///
28    /// Propagates repository errors.
29    fn is_working_tree_clean(&self, project_root: &Path) -> Result<bool>;
30
31    /// # Errors
32    ///
33    /// Propagates repository errors.
34    fn current_branch(&self, project_root: &Path) -> Result<String>;
35
36    /// # Errors
37    ///
38    /// Propagates repository errors.
39    fn remote_url(&self, project_root: &Path) -> Result<Option<String>>;
40}
41
42pub trait GitStagingProvider: Send + Sync {
43    /// # Errors
44    ///
45    /// Propagates repository errors.
46    fn stage_files(&self, project_root: &Path, paths: &[&Path]) -> Result<()>;
47
48    /// Fail-fast: if any file does not exist or cannot be deleted,
49    /// returns an error immediately and no further files are processed.
50    ///
51    /// # Errors
52    ///
53    /// Propagates repository errors.
54    fn delete_files(&self, project_root: &Path, paths: &[&Path]) -> Result<()>;
55}
56
57pub trait GitCommitProvider: Send + Sync {
58    /// # Errors
59    ///
60    /// Propagates repository errors.
61    fn commit(&self, project_root: &Path, message: &str) -> Result<CommitInfo>;
62
63    /// Soft reset to HEAD~1, undoing the last commit while keeping changes staged.
64    ///
65    /// # Errors
66    ///
67    /// Propagates repository errors.
68    fn reset_to_parent(&self, project_root: &Path) -> Result<()>;
69}
70
71pub trait GitTagProvider: Send + Sync {
72    /// # Errors
73    ///
74    /// Propagates repository errors.
75    fn create_tag(&self, project_root: &Path, tag_name: &str, message: &str) -> Result<TagInfo>;
76
77    /// Returns `Ok(true)` if deleted, `Ok(false)` if not found.
78    ///
79    /// # Errors
80    ///
81    /// Propagates repository errors.
82    fn delete_tag(&self, project_root: &Path, tag_name: &str) -> Result<bool>;
83}