workyard_core/ports/
git.rs1use crate::{Control, Problem};
2use std::{
3 future::Future,
4 path::{Path, PathBuf},
5};
6
7#[derive(Clone, Debug)]
9pub struct Repository {
10 pub source: PathBuf,
12 pub common_dir: PathBuf,
14 pub remote: Option<String>,
16 pub identity: String,
18}
19
20#[derive(Clone, Debug)]
22pub enum BranchPlan {
23 Reuse,
25 Track(String),
27 Create(String),
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq)]
33pub enum SourceResolution {
34 Cached,
36 FetchPending,
38}
39
40pub trait Git: Sync {
42 fn worktree_identity(
44 &self,
45 _path: &Path,
46 ) -> impl Future<Output = Result<Option<String>, Problem>> + Send {
47 async { Ok(None) }
48 }
49
50 fn validate_branch(
52 &self,
53 root: &Path,
54 task: &str,
55 control: &Control,
56 ) -> impl Future<Output = Result<(), Problem>> + Send;
57
58 fn inspect(
60 &self,
61 path: &Path,
62 remote: Option<&str>,
63 control: &Control,
64 ) -> impl Future<Output = Result<Repository, Problem>> + Send;
65
66 fn revalidate(
68 &self,
69 repository: &Repository,
70 control: &Control,
71 ) -> impl Future<Output = Result<(), Problem>> + Send;
72
73 fn plan(
75 &self,
76 repository: &Repository,
77 task: &str,
78 checkout: bool,
79 from: Option<&str>,
80 resolution: SourceResolution,
81 control: &Control,
82 ) -> impl Future<Output = Result<BranchPlan, Problem>> + Send;
83
84 fn fetch(
86 &self,
87 repository: &Repository,
88 control: &Control,
89 ) -> impl Future<Output = Result<(), Problem>> + Send;
90
91 fn add(
93 &self,
94 repository: &Repository,
95 task: &str,
96 destination: &Path,
97 plan: &BranchPlan,
98 control: &Control,
99 ) -> impl Future<Output = Result<(), Problem>> + Send;
100}
101
102pub trait RecoveryGit: Git {
104 fn recovery_relationship(
106 &self,
107 _participant: &crate::Participant,
108 _control: &Control,
109 ) -> impl Future<Output = Result<Option<crate::Relationship>, Problem>> + Send {
110 async { Ok(None) }
111 }
112
113 fn repair_relationship(
115 &self,
116 _repository: &Repository,
117 _participant: &crate::Participant,
118 _control: &Control,
119 ) -> impl Future<Output = Result<(), Problem>> + Send {
120 async {
121 Err(Problem::new(
122 crate::ProblemCode::RepositoryChanged,
123 "Git adapter does not support relationship repair.",
124 ))
125 }
126 }
127
128 fn reconcile(
130 &self,
131 participant: &crate::Participant,
132 task: &str,
133 control: &Control,
134 ) -> impl Future<Output = Result<crate::RecoveryObservation, Problem>> + Send;
135}