rskit_git/manage.rs
1//! Repository management traits.
2
3use rskit_errors::AppResult;
4
5use crate::options::{CleanOptions, FetchOptions, PushOptions};
6use crate::types::{Branch, BranchFilter, Remote, Tag};
7
8/// Read and manage git references.
9pub trait RefManager {
10 /// Lists branches matching the requested filter.
11 fn list_branches(&self, filter: BranchFilter) -> AppResult<Vec<Branch>>;
12
13 /// Lists tags in the repository.
14 fn list_tags(&self) -> AppResult<Vec<Tag>>;
15
16 /// Creates a local branch pointing at the given target revision.
17 fn create_branch(&self, name: &str, target: &str) -> AppResult<()>;
18
19 /// Deletes a local branch.
20 fn delete_branch(&self, name: &str) -> AppResult<()>;
21
22 /// Creates a tag pointing at the given target revision.
23 /// `Some(message)` creates an annotated tag (with tagger and the given message, which may be empty);
24 /// `None` creates a lightweight tag (a plain ref). Both backends must follow this convention.
25 fn create_tag(&self, name: &str, target: &str, message: Option<&str>) -> AppResult<()>;
26
27 /// Deletes a tag.
28 fn delete_tag(&self, name: &str) -> AppResult<()>;
29}
30
31/// Read and manage git remotes.
32pub trait RemoteManager {
33 /// Lists configured remotes.
34 fn list_remotes(&self) -> AppResult<Vec<Remote>>;
35
36 /// Fetches updates from a remote.
37 fn fetch(&self, remote: &str, opts: Option<&FetchOptions>) -> AppResult<()>;
38
39 /// Pushes refs to a remote.
40 fn push(&self, remote: &str, opts: Option<&PushOptions>) -> AppResult<()>;
41
42 /// Returns the configured upstream tracking branch for a local branch.
43 fn tracking_branch(&self, branch: &str) -> AppResult<String>;
44}
45
46/// Read and update git configuration.
47pub trait ConfigReader {
48 /// Returns the highest-precedence value for a config key.
49 fn config_get(&self, key: &str) -> AppResult<String>;
50
51 /// Returns all configured values for a multivar config key.
52 fn config_get_all(&self, key: &str) -> AppResult<Vec<String>>;
53
54 /// Sets a config key in the repository configuration.
55 fn config_set(&self, key: &str, value: &str) -> AppResult<()>;
56}
57
58/// Repository maintenance operations.
59pub trait Maintainer {
60 /// Runs repository garbage collection.
61 fn gc(&self) -> AppResult<()>;
62
63 /// Prunes unreachable objects.
64 fn prune(&self) -> AppResult<()>;
65
66 /// Verifies repository object integrity.
67 fn fsck(&self) -> AppResult<()>;
68
69 /// Cleans untracked files according to the provided options.
70 fn clean(&self, opts: Option<&CleanOptions>) -> AppResult<Vec<String>>;
71}