workyard_core/model/creation.rs
1use std::path::PathBuf;
2
3/// Policy shared by initial creation and participant additions.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub struct CreationOptions {
6 /// Allow reuse of an existing target branch.
7 pub checkout: bool,
8 /// Use locally available refs without fetching.
9 pub no_fetch: bool,
10}
11
12/// Repository selection and its per-participant overrides.
13#[derive(Clone, Debug)]
14pub struct RepositoryInput {
15 /// Explicit source spellings to register once the worktree is admitted.
16 pub registration_roots: Vec<PathBuf>,
17 /// Backing identity observed when resolving a tracked reference.
18 pub expected_identity: Option<String>,
19 /// Path to the backing repository selected by the caller.
20 pub path: PathBuf,
21 /// Optional override for the participant’s directory name inside the task.
22 pub name: Option<String>,
23 /// Remote selected for branch resolution or fetch.
24 pub remote: Option<String>,
25 /// Starting revision for a newly created branch.
26 pub from: Option<String>,
27}
28
29impl RepositoryInput {
30 pub(crate) fn verify_identity(
31 &self,
32 repository: &crate::Repository,
33 ) -> Result<(), crate::Problem> {
34 if self
35 .expected_identity
36 .as_ref()
37 .is_some_and(|expected| expected != &repository.identity)
38 {
39 return Err(crate::Problem::new(
40 crate::ProblemCode::RepositoryChanged,
41 format!(
42 "The tracked repository at {:?} changed during selection.",
43 self.path
44 ),
45 )
46 .remedy("Inspect the project location and retry the command."));
47 }
48 Ok(())
49 }
50}
51
52/// Resolved workspace placement, participants and branch options for task creation.
53#[derive(Clone, Debug)]
54pub struct CreateRequest {
55 /// Task selected for this operation.
56 pub task: String,
57 /// Backing repositories selected for membership.
58 pub repositories: Vec<RepositoryInput>,
59 /// Directory containing the task workspaces.
60 pub tasks_root: PathBuf,
61 /// Directory holding authoritative Workyard state.
62 pub state_dir: PathBuf,
63 /// Allow reuse of an existing target branch.
64 pub checkout: bool,
65 /// Use locally available refs without fetching.
66 pub no_fetch: bool,
67 /// Remote selected for branch resolution or fetch.
68 pub remote: Option<String>,
69 /// Starting revision for a newly created branch.
70 pub from: Option<String>,
71}
72
73/// Task facts and invocation outcome returned by creation.
74pub struct CreateResult {
75 /// Task selected for this operation.
76 pub task: crate::Task,
77 /// Location of the task record when available.
78 pub record: PathBuf,
79 /// Invocation history tracked separately from task lifecycle.
80 pub operation: crate::Operation,
81 /// Diagnostic describing a failure or an unresolved condition.
82 pub problem: Option<crate::Problem>,
83}