Skip to main content

chronicle/git/
mod.rs

1pub mod cli_ops;
2pub mod diff;
3
4pub use cli_ops::CliOps;
5pub use diff::{DiffStatus, FileDiff, Hunk, HunkLine};
6
7use crate::error::GitError;
8use std::path::Path;
9
10/// Metadata about a commit.
11#[derive(Debug, Clone)]
12pub struct CommitInfo {
13    pub sha: String,
14    pub message: String,
15    pub author_name: String,
16    pub author_email: String,
17    pub timestamp: String,
18    pub parent_shas: Vec<String>,
19}
20
21/// Abstraction over git operations. MVP implements CliOps (shelling out to git).
22/// GixOps (pure Rust via gitoxide) will be added later.
23pub trait GitOps: Send + Sync {
24    /// Get the diff for a single commit.
25    fn diff(&self, commit: &str) -> Result<Vec<FileDiff>, GitError>;
26
27    /// Read a git note from the chronicle notes ref.
28    fn note_read(&self, commit: &str) -> Result<Option<String>, GitError>;
29
30    /// Write a git note to the chronicle notes ref (overwrites existing).
31    fn note_write(&self, commit: &str, content: &str) -> Result<(), GitError>;
32
33    /// Check if a note exists for a commit.
34    fn note_exists(&self, commit: &str) -> Result<bool, GitError>;
35
36    /// Read a file at a specific commit.
37    fn file_at_commit(&self, path: &Path, commit: &str) -> Result<String, GitError>;
38
39    /// Get commit metadata.
40    fn commit_info(&self, commit: &str) -> Result<CommitInfo, GitError>;
41
42    /// Resolve a ref (branch name, HEAD, etc.) to a SHA.
43    fn resolve_ref(&self, refspec: &str) -> Result<String, GitError>;
44
45    /// Read a git config value.
46    fn config_get(&self, key: &str) -> Result<Option<String>, GitError>;
47
48    /// Set a git config value.
49    fn config_set(&self, key: &str, value: &str) -> Result<(), GitError>;
50
51    /// List commit SHAs that touched a file (newest first), following renames.
52    fn log_for_file(&self, path: &str) -> Result<Vec<String>, GitError>;
53
54    /// List commit SHAs that have chronicle notes (newest first), up to `limit`.
55    fn list_annotated_commits(&self, limit: u32) -> Result<Vec<String>, GitError>;
56}