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
24 /// message, which may be empty); `None` creates a lightweight tag (a plain
25 /// ref). Both backends must follow this convention.
26 fn create_tag(&self, name: &str, target: &str, message: Option<&str>) -> AppResult<()>;
27
28 /// Deletes a tag.
29 fn delete_tag(&self, name: &str) -> AppResult<()>;
30}
31
32/// Read and manage git remotes.
33pub trait RemoteManager {
34 /// Lists configured remotes.
35 fn list_remotes(&self) -> AppResult<Vec<Remote>>;
36
37 /// Fetches updates from a remote.
38 fn fetch(&self, remote: &str, opts: Option<&FetchOptions>) -> AppResult<()>;
39
40 /// Pushes refs to a remote.
41 fn push(&self, remote: &str, opts: Option<&PushOptions>) -> AppResult<()>;
42
43 /// Returns the configured upstream tracking branch for a local branch.
44 fn tracking_branch(&self, branch: &str) -> AppResult<String>;
45}
46
47/// Read and update git configuration.
48pub trait ConfigReader {
49 /// Returns the highest-precedence value for a config key.
50 fn config_get(&self, key: &str) -> AppResult<String>;
51
52 /// Returns all configured values for a multivar config key.
53 fn config_get_all(&self, key: &str) -> AppResult<Vec<String>>;
54
55 /// Sets a config key in the repository configuration.
56 fn config_set(&self, key: &str, value: &str) -> AppResult<()>;
57}
58
59/// Repository maintenance operations.
60pub trait Maintainer {
61 /// Runs repository garbage collection.
62 fn gc(&self) -> AppResult<()>;
63
64 /// Prunes unreachable objects.
65 fn prune(&self) -> AppResult<()>;
66
67 /// Verifies repository object integrity.
68 fn fsck(&self) -> AppResult<()>;
69
70 /// Cleans untracked files according to the provided options.
71 fn clean(&self, opts: Option<&CleanOptions>) -> AppResult<Vec<String>>;
72}