Skip to main content

rskit_git/
write.rs

1//! Write-oriented git traits.
2
3use rskit_errors::AppResult;
4
5use crate::options::{
6    CheckoutOptions, CherryPickOptions, CommitOptions, MergeOptions, RebaseOptions,
7};
8use crate::types::{MergeResult, Oid, RebaseResult, ResetMode, StashEntry, StatusEntry};
9
10/// Stage and unstage repository paths through the git index.
11pub trait IndexManager {
12    /// Stages the provided repository-relative paths.
13    fn stage(&self, paths: &[&str]) -> AppResult<()>;
14
15    /// Removes the provided repository-relative paths from the index.
16    fn unstage(&self, paths: &[&str]) -> AppResult<()>;
17
18    /// Lists entries that currently differ between HEAD and the index.
19    fn staged_entries(&self) -> AppResult<Vec<StatusEntry>>;
20}
21
22/// Creates new commits from the repository index.
23pub trait Committer {
24    /// Creates a commit from the current index state and returns its object ID.
25    fn commit(&self, message: &str, opts: Option<&CommitOptions>) -> AppResult<Oid>;
26}
27
28/// Merge operations.
29pub trait Merger {
30    /// Merges a branch into the current HEAD.
31    fn merge(&self, branch: &str, opts: Option<&MergeOptions>) -> AppResult<MergeResult>;
32
33    /// Aborts an in-progress merge.
34    fn abort_merge(&self) -> AppResult<()>;
35
36    /// Aborts an in-progress merge.
37    fn merge_abort(&self) -> AppResult<()> {
38        self.abort_merge()
39    }
40}
41
42/// Rebase operations.
43pub trait Rebaser {
44    /// Rebases the current branch onto another target.
45    fn rebase(&self, onto: &str, opts: Option<&RebaseOptions>) -> AppResult<RebaseResult>;
46
47    /// Aborts an in-progress rebase.
48    fn abort_rebase(&self) -> AppResult<()>;
49
50    /// Continues an in-progress rebase.
51    fn continue_rebase(&self) -> AppResult<RebaseResult>;
52
53    /// Aborts an in-progress rebase.
54    fn rebase_abort(&self) -> AppResult<()> {
55        self.abort_rebase()
56    }
57
58    /// Continues an in-progress rebase.
59    fn rebase_continue(&self) -> AppResult<RebaseResult> {
60        self.continue_rebase()
61    }
62}
63
64/// Cherry-pick operations.
65pub trait CherryPicker {
66    /// Cherry-picks the given commit.
67    fn cherry_pick(&self, commit: &str, opts: Option<&CherryPickOptions>) -> AppResult<Oid>;
68
69    /// Continues an in-progress cherry-pick.
70    fn cherry_pick_continue(&self) -> AppResult<Oid>;
71
72    /// Aborts an in-progress cherry-pick.
73    fn cherry_pick_abort(&self) -> AppResult<()>;
74}
75
76/// Reset operations.
77pub trait Resetter {
78    /// Resets repository state to the target revision.
79    fn reset(&self, target: &str, mode: ResetMode) -> AppResult<()>;
80}
81
82/// Checkout operations.
83pub trait CheckoutManager {
84    /// Checks out the given ref.
85    fn checkout(&self, ref_name: &str, opts: Option<&CheckoutOptions>) -> AppResult<()>;
86
87    /// Checks out the provided paths from the index or HEAD.
88    fn checkout_files(&self, paths: &[&str]) -> AppResult<()>;
89}
90
91/// Stash operations.
92pub trait Stasher {
93    /// Creates a stash entry.
94    fn stash(&self, message: &str) -> AppResult<Oid>;
95
96    /// Creates a stash entry.
97    fn stash_push(&self, message: &str) -> AppResult<Oid> {
98        self.stash(message)
99    }
100
101    /// Applies and drops the top stash entry.
102    fn stash_pop(&self) -> AppResult<()>;
103
104    /// Applies and drops the selected stash entry.
105    fn stash_pop_index(&self, index: usize) -> AppResult<()>;
106
107    /// Lists stash entries.
108    fn stash_list(&self) -> AppResult<Vec<StashEntry>>;
109}