Skip to main content

sr_core/
git.rs

1use semver::Version;
2
3use crate::commit::Commit;
4use crate::error::ReleaseError;
5
6/// Information about a git tag.
7#[derive(Debug, Clone)]
8pub struct TagInfo {
9    pub name: String,
10    pub version: Version,
11    pub sha: String,
12}
13
14/// Abstraction over git operations.
15pub trait GitRepository: Send + Sync {
16    /// Find the latest semver tag matching the configured prefix.
17    fn latest_tag(&self, prefix: &str) -> Result<Option<TagInfo>, ReleaseError>;
18
19    /// List commits between a starting point (exclusive) and HEAD (inclusive).
20    /// If `from` is `None`, returns all commits reachable from HEAD.
21    fn commits_since(&self, from: Option<&str>) -> Result<Vec<Commit>, ReleaseError>;
22
23    /// Create an annotated tag at HEAD.
24    fn create_tag(&self, name: &str, message: &str) -> Result<(), ReleaseError>;
25
26    /// Push a tag to the remote.
27    fn push_tag(&self, name: &str) -> Result<(), ReleaseError>;
28
29    /// Stage files and commit. Returns Ok(false) if nothing to commit.
30    fn stage_and_commit(&self, paths: &[&str], message: &str) -> Result<bool, ReleaseError>;
31
32    /// Push current branch to origin.
33    fn push(&self) -> Result<(), ReleaseError>;
34
35    /// Check if a tag exists locally.
36    fn tag_exists(&self, name: &str) -> Result<bool, ReleaseError>;
37
38    /// Check if a tag exists on the remote.
39    fn remote_tag_exists(&self, name: &str) -> Result<bool, ReleaseError>;
40
41    /// List all semver tags matching prefix, sorted by version ascending.
42    fn all_tags(&self, prefix: &str) -> Result<Vec<TagInfo>, ReleaseError>;
43
44    /// List commits between two refs (exclusive `from`, inclusive `to`).
45    /// If `from` is None, returns all commits reachable from `to`.
46    fn commits_between(&self, from: Option<&str>, to: &str) -> Result<Vec<Commit>, ReleaseError>;
47
48    /// Get the date (YYYY-MM-DD) of the commit a tag points to.
49    fn tag_date(&self, tag_name: &str) -> Result<String, ReleaseError>;
50
51    /// Force-create an annotated tag at HEAD, overwriting if it already exists.
52    fn force_create_tag(&self, name: &str, message: &str) -> Result<(), ReleaseError>;
53
54    /// Force-push a tag to the remote, overwriting the remote tag if it exists.
55    fn force_push_tag(&self, name: &str) -> Result<(), ReleaseError>;
56
57    /// Return the full SHA of HEAD.
58    fn head_sha(&self) -> Result<String, ReleaseError>;
59}