Skip to main content

workyard_git/repository/
effects.rs

1use super::Repository;
2use crate::{Runner, process::args};
3use std::path::Path;
4use workyard_core::BranchPlan;
5use workyard_core::{Control, Problem};
6
7impl Repository {
8	/// Refresh refs from the selected remote under Workyard's fetch coordination.
9	pub async fn fetch(&self, runner: &Runner, control: &Control) -> Result<(), Problem> {
10		if let Some(remote) = &self.remote {
11			runner
12				.effect(&self.source, &args(&["fetch", "--", remote]), control)
13				.await?;
14		}
15
16		Ok(())
17	}
18
19	/// Create the linked worktree using the resolved branch plan.
20	pub async fn add(
21		&self,
22		runner: &Runner,
23		task: &str,
24		destination: &Path,
25		plan: &BranchPlan,
26		control: &Control,
27	) -> Result<(), Problem> {
28		let mut arguments = args(&["worktree", "add"]);
29		match plan {
30			BranchPlan::Reuse => {
31				arguments.push("--".into());
32				arguments.push(dunce::simplified(destination).into());
33				arguments.push(task.into());
34			}
35			BranchPlan::Track(source) => {
36				arguments.extend(args(&["--track", "-b", task, "--"]));
37				arguments.push(dunce::simplified(destination).into());
38				arguments.push(source.into());
39			}
40			BranchPlan::Create(source) => {
41				arguments.extend(args(&["-b", task, "--"]));
42				arguments.push(dunce::simplified(destination).into());
43				arguments.push(source.into());
44			}
45		}
46		runner.effect(&self.source, &arguments, control).await?;
47		Ok(())
48	}
49}