workyard-git 0.1.0

Git worktree inspection and process supervision for Workyard
Documentation
use super::Repository;
use crate::{Runner, process::args};
use std::path::Path;
use workyard_core::BranchPlan;
use workyard_core::{Control, Problem};

impl Repository {
	/// Refresh refs from the selected remote under Workyard's fetch coordination.
	pub async fn fetch(&self, runner: &Runner, control: &Control) -> Result<(), Problem> {
		if let Some(remote) = &self.remote {
			runner
				.effect(&self.source, &args(&["fetch", "--", remote]), control)
				.await?;
		}

		Ok(())
	}

	/// Create the linked worktree using the resolved branch plan.
	pub async fn add(
		&self,
		runner: &Runner,
		task: &str,
		destination: &Path,
		plan: &BranchPlan,
		control: &Control,
	) -> Result<(), Problem> {
		let mut arguments = args(&["worktree", "add"]);
		match plan {
			BranchPlan::Reuse => {
				arguments.push("--".into());
				arguments.push(dunce::simplified(destination).into());
				arguments.push(task.into());
			}
			BranchPlan::Track(source) => {
				arguments.extend(args(&["--track", "-b", task, "--"]));
				arguments.push(dunce::simplified(destination).into());
				arguments.push(source.into());
			}
			BranchPlan::Create(source) => {
				arguments.extend(args(&["-b", task, "--"]));
				arguments.push(dunce::simplified(destination).into());
				arguments.push(source.into());
			}
		}
		runner.effect(&self.source, &arguments, control).await?;
		Ok(())
	}
}