1use crate::{Control, Git, Participant, Problem, Repository};
2use std::{future::Future, path::PathBuf};
3
4#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum RetainedHistory {
7 UpToDate,
9 Unpushed,
11 NoUpstream,
13 Detached,
15}
16
17#[derive(Clone, Debug)]
19pub struct RemovalObservation {
20 pub administration_identity: String,
22 pub worktree_entry: (u64, u64),
24 pub repository: Repository,
26 pub destination: Option<PathBuf>,
28 pub branch: Option<String>,
30 pub dirty_paths: Vec<PathBuf>,
32 pub dirty_token: Vec<u8>,
34 pub history: RetainedHistory,
36}
37
38impl RemovalObservation {
39 pub(crate) fn same_worktree(&self, other: &Self) -> bool {
40 self.destination == other.destination
41 && self.administration_identity == other.administration_identity
42 && self.worktree_entry == other.worktree_entry
43 }
44}
45
46#[derive(Debug)]
48pub enum UnlinkFailure {
49 BeforeLaunch(Problem),
51 Command(Problem),
53}
54
55impl From<Problem> for UnlinkFailure {
56 fn from(problem: Problem) -> Self {
57 Self::BeforeLaunch(problem)
58 }
59}
60
61pub trait RemovalGit: Git {
63 fn reconcile_recreation(
65 &self,
66 participant: &Participant,
67 branch: &str,
68 control: &Control,
69 ) -> impl Future<Output = Result<crate::RecoveryObservation, Problem>> + Send;
70
71 fn reconcile_restored(
73 &self,
74 participant: &Participant,
75 control: &Control,
76 ) -> impl Future<Output = Result<crate::RecoveryObservation, Problem>> + Send;
77
78 fn inspect_removal(
80 &self,
81 participant: &Participant,
82 control: &Control,
83 ) -> impl Future<Output = Result<RemovalObservation, Problem>> + Send;
84
85 fn remove_worktree(
87 &self,
88 observation: &RemovalObservation,
89 discard: bool,
90 control: &Control,
91 before_unlink: impl FnOnce() -> Result<(), Problem> + Send,
92 ) -> impl Future<Output = Result<(), UnlinkFailure>> + Send;
93
94 fn inspect_restoration(
96 &self,
97 participant: &Participant,
98 branch: &str,
99 control: &Control,
100 ) -> impl Future<Output = Result<Repository, Problem>> + Send;
101}
102
103#[derive(Clone, Copy, Debug, PartialEq, Eq)]
105pub enum DecisionKind {
106 RemoveTask,
108 RemoveParticipants,
110 DiscardParticipants,
112 DiscardTask,
114 DiscardFiles,
116 RetainedHistory,
118 LostChanges,
120}
121
122#[derive(Clone, Debug)]
124pub struct Decision {
125 pub task: Option<String>,
127 pub kind: DecisionKind,
129 pub participant: String,
131 pub participants: Vec<String>,
133 pub message: String,
135}
136
137pub trait RemovalObserver: crate::Observer {
139 fn begin_disclosure(&self, _task: &crate::Task, _amendment: Option<&crate::AmendRequest>) {}
141
142 fn requires_unchanged_disclosure(&self) -> bool {
144 false
145 }
146
147 fn disclose(
149 &self,
150 _participant: &str,
151 _observation: &RemovalObservation,
152 ) -> impl Future<Output = Result<(), Problem>> + Send {
153 async { Ok(()) }
154 }
155
156 fn removed(
158 &self,
159 task: &str,
160 participant: &str,
161 ) -> impl Future<Output = Result<(), Problem>> + Send {
162 self.phase(task, participant, "removed")
163 }
164
165 fn confirm(
167 &self,
168 _decision: Decision,
169 ) -> impl Future<Output = Result<Option<bool>, Problem>> + Send {
170 async { Ok(None) }
171 }
172}
173
174#[derive(Clone, Copy, Debug, Default)]
176pub struct RemovalOptions {
177 pub yes: bool,
179 pub force: bool,
181 pub undo: bool,
183}