Skip to main content

workyard_core/ports/
amendment.rs

1use crate::{
2	AmendRequest, Control, Participant, Problem, RecoveryGit, RecoveryState, Repository, Task,
3};
4use std::{future::Future, path::Path};
5
6/// A participant reconciled with its observed Git registration.
7pub struct Relationship {
8	/// Participant to which this observation or change applies.
9	pub participant: Participant,
10	/// Whether the Git links require reconciliation.
11	pub needs_repair: bool,
12}
13
14/// Git operations required to add, move and reconcile participants.
15pub trait AmendGit: RecoveryGit + crate::RemovalGit + crate::ObservationGit {
16	/// Locate the registered participant and determine whether its links need repair.
17	fn relationship(
18		&self,
19		repository: &Repository,
20		participant: &Participant,
21		control: &Control,
22	) -> impl Future<Output = Result<Relationship, Problem>> + Send;
23
24	/// Repair the relationship for the verified participant.
25	fn repair(
26		&self,
27		repository: &Repository,
28		participant: &Participant,
29		control: &Control,
30	) -> impl Future<Output = Result<(), Problem>> + Send;
31
32	/// Ask Git to move the participant worktree to its destination.
33	fn move_worktree(
34		&self,
35		repository: &Repository,
36		participant: &Participant,
37		destination: &Path,
38		control: &Control,
39	) -> impl Future<Output = Result<(), Problem>> + Send;
40}
41
42/// Persistent intent and checkpoints needed for a resumable amendment.
43pub trait AmendState: RecoveryState {
44	/// State saved before amendment effects begin.
45	type Checkpoint: Send;
46	/// May a private staging name be used without adopting an existing entry?
47	fn staging_available(&self, path: &Path) -> Result<bool, Problem>;
48
49	/// Does this sibling spelling identify the same directory on this volume?
50	fn same_destination(&self, left: &Path, right: &Path) -> Result<bool, Problem>;
51
52	/// Record the requested changes and bind their removal targets.
53	fn begin_amend(
54		&self,
55		guard: &Self::Admission,
56		task: &Task,
57		request: &AmendRequest,
58		targets: &[crate::RemovalTarget],
59	) -> Result<Self::Checkpoint, Problem>;
60
61	/// Read the participants bound to the pending removal.
62	fn removal_targets(
63		&self,
64		guard: &Self::Admission,
65	) -> Result<Vec<crate::RemovalTarget>, Problem>;
66
67	/// Publish confirmed unlink and compacted membership as a single revision.
68	fn settle_unlink(
69		&self,
70		guard: &Self::Admission,
71		task: &Task,
72		target: &crate::RemovalTarget,
73	) -> Result<(), Problem>;
74
75	/// Restore the checkpoint when the amendment produced no effects.
76	fn unchanged_amend(
77		&self,
78		guard: &Self::Admission,
79		checkpoint: Self::Checkpoint,
80	) -> Result<(), Problem>;
81
82	/// Read the recorded request for amendment recovery.
83	fn amend_request(&self, guard: &Self::Admission) -> Result<Option<AmendRequest>, Problem>;
84}