pub struct WorktreeService { /* private fields */ }Expand description
The repository’s worktrees, decided once.
Built from a directory — any directory inside any work tree — and nothing else.
Implementations§
Source§impl WorktreeService
impl WorktreeService
Sourcepub fn open(start: &Path) -> Result<Self>
pub fn open(start: &Path) -> Result<Self>
Resolve the repository from start. The scratch roots come from the distribution’s
provider declarations, located the way every command locates the share; a checkout
with no share in reach declares none, and a temporary checkout is then what its path
says it is.
Sourcepub fn over(identity: RepositoryIdentity) -> Result<Self>
pub fn over(identity: RepositoryIdentity) -> Result<Self>
The service over an identity already resolved.
Sourcepub fn over_with(
identity: RepositoryIdentity,
scratch_roots: Vec<ScratchRoot>,
) -> Result<Self>
pub fn over_with( identity: RepositoryIdentity, scratch_roots: Vec<ScratchRoot>, ) -> Result<Self>
The service over an identity, with the scratch roots given rather than located.
Sourcepub fn scratch_roots(&self) -> &[ScratchRoot]
pub fn scratch_roots(&self) -> &[ScratchRoot]
The scratch roots in force, expanded.
Sourcepub fn identity(&self) -> &RepositoryIdentity
pub fn identity(&self) -> &RepositoryIdentity
The repository this service speaks for.
Sourcepub fn container(&self) -> &ResolvedPath
pub fn container(&self) -> &ResolvedPath
The canonical container.
Sourcepub fn expected_path_of(&self, branch: &str) -> Result<PathBuf>
pub fn expected_path_of(&self, branch: &str) -> Result<PathBuf>
Where the worktree of branch belongs.
Sourcepub fn judge(
&self,
record: &WorktreeRecord,
detail: Detail,
branches: &BTreeMap<String, BranchRef>,
) -> WorktreeState
pub fn judge( &self, record: &WorktreeRecord, detail: Detail, branches: &BTreeMap<String, BranchRef>, ) -> WorktreeState
Everything the topology says about one registered work tree. The one place a standing is decided.
Sourcepub fn scratch_root_of(&self, path: &ResolvedPath) -> Option<ScratchRoot>
pub fn scratch_root_of(&self, path: &ResolvedPath) -> Option<ScratchRoot>
The scratch root a path lies under, when it does. The roots are the declarations’
(share/providers.yaml): the tool’s own temporary directories and every provider’s,
such as .claude/worktrees/ under the primary checkout, which Claude Code creates and
removes with the session that asked for it, or the thread directory an orchestrator
keeps under its data directory. A root the primary checkout itself lives under is
skipped, as a test fixture’s temporary directory is: nothing beside the repository
is a scratch checkout of it.
Sourcepub fn ephemeral_root_of(&self, path: &ResolvedPath) -> Option<PathBuf>
pub fn ephemeral_root_of(&self, path: &ResolvedPath) -> Option<PathBuf>
Self::scratch_root_of, the path alone.
Sourcepub fn topology(&self, detail: Detail) -> Result<RepositoryTopology>
pub fn topology(&self, detail: Detail) -> Result<RepositoryTopology>
The whole topology.
Sourcepub fn status(&self) -> Result<StatusReport>
pub fn status(&self) -> Result<StatusReport>
Where this call is, and whether that is where it belongs.
Sourcepub fn guard(&self) -> Result<GuardVerdict>
pub fn guard(&self) -> Result<GuardVerdict>
The guard: may a mutation proceed from the work tree this call came from?
Sourcepub fn inspect(&self, branch: &str) -> Result<InspectReport>
pub fn inspect(&self, branch: &str) -> Result<InspectReport>
One branch: where its worktree belongs and what is there.
Sourcepub fn resolve(&self, selector: &str) -> Result<WorktreeRecord>
pub fn resolve(&self, selector: &str) -> Result<WorktreeRecord>
Resolve a selector to exactly one registered work tree: an exact branch name, or an exact path. Nothing is matched by prefix, substring or similarity — these selectors are given to commands that delete things.
Sourcepub fn create(&self, request: &CreateRequest) -> Result<CreateReport>
pub fn create(&self, request: &CreateRequest) -> Result<CreateReport>
Create the canonical worktree of a branch. The destination is derived and never given. Everything that could go wrong is checked before git is asked to do anything, so a refusal leaves the repository exactly as it was.
Sourcepub fn ensure(&self, request: &CreateRequest) -> Result<CreateReport>
pub fn ensure(&self, request: &CreateRequest) -> Result<CreateReport>
The same, answering the existing canonical worktree rather than refusing when it is already there.
Sourcepub fn remove(&self, selector: &str, force: bool) -> Result<RemoveReport>
pub fn remove(&self, selector: &str, force: bool) -> Result<RemoveReport>
Remove one linked worktree. Never a branch, never the primary checkout, never
uncommitted work without force.
Sourcepub fn repair(&self, dry_run: bool) -> Result<RepairReport>
pub fn repair(&self, dry_run: bool) -> Result<RepairReport>
Drop the registrations of work trees whose directories are gone, and let git repair the administrative links of the ones that exist. Deletes no directory.
Source§impl WorktreeService
impl WorktreeService
Sourcepub fn uncommitted(&self, threshold: &Threshold) -> Result<UncommittedReport>
pub fn uncommitted(&self, threshold: &Threshold) -> Result<UncommittedReport>
Every linked work tree holding uncommitted work, with how much, how old, what holds
it and whether it is abandoned against threshold. Reads every work tree and writes
none: see the module documentation.
use majordomus_cli::worktree::{Threshold, WorkStanding, WorktreeService};
use std::path::Path;
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let git = |cwd: &Path, args: &[&str]| {
let ok = Command::new("git")
.args(["-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false"])
.args(args)
.current_dir(cwd)
.status()
.unwrap();
assert!(ok.success(), "git {args:?}");
};
let repo = dir.path().join("repo");
std::fs::create_dir_all(&repo).unwrap();
git(&repo, &["init", "-q"]);
git(&repo, &["commit", "-q", "--allow-empty", "-m", "init"]);
let (clean, dirty) = (dir.path().join("clean"), dir.path().join("dirty"));
git(&repo, &["worktree", "add", "-q", "-b", "work/clean", clean.to_str().unwrap()]);
git(&repo, &["worktree", "add", "-q", "-b", "work/dirty", dirty.to_str().unwrap()]);
std::fs::write(dirty.join("new.txt"), "work\n").unwrap();
let threshold = Threshold::resolve(Some("12h"), None).unwrap();
let report = WorktreeService::open(&repo).unwrap().uncommitted(&threshold).unwrap();
assert_eq!(report.tallies.measured, 2, "both linked work trees were read");
assert_eq!(report.worktrees.len(), 1, "only the one with work is listed");
let w = &report.worktrees[0];
assert_eq!((w.label.as_str(), w.paths, w.work.untracked), ("work/dirty", 1, 1));
assert_eq!(w.standing, WorkStanding::Recent, "written a moment ago");Trait Implementations§
Source§impl Clone for WorktreeService
impl Clone for WorktreeService
Source§fn clone(&self) -> WorktreeService
fn clone(&self) -> WorktreeService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more