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