git_policy_cli/worktree/worktree_ladder.rs
1//! What:
2//! The cheap-worktree ladder around one `git worktree add`: what runs before real Git and after it, on Linux; on other
3//! systems the ladder does nothing and Git's own checkout stands.
4//! Why:
5//! `doc/planning/cli-git-btrfs-worktree.md` designs the ladder and measures it: a snapshot of a clean subvolume
6//! worktree, then clones of its tracked files, then Git's own checkout. The lifecycle of the copy
7//! (`worktree_copy.rs`) calls this one module, so the rungs stay out of its settlement and recovery code.
8//!
9//! In TS you'd write (pseudocode):
10//! ```ts
11//! const ladder = beginLadder(plan, context, identity);
12//! const git = await runGit(ladder.firstStep());
13//! const { git: status, carried } = await ladder.finish(git, ...);
14//! ```
15
16#[cfg(target_os = "linux")]
17pub use crate::worktree_ladder_run::{Ladder, LadderResult, begin_ladder};
18
19/// What:
20/// The ladder on a system without btrfs subvolumes and snapshots: nothing is prepared and nothing is settled.
21/// Why:
22/// Git's own checkout stands there, and the lifecycle calls the same four names.
23///
24/// In TS you'd write (pseudocode):
25/// ```ts
26/// const ladder = beginLadder(plan, context, identity); // does nothing
27/// ```
28#[cfg(not(target_os = "linux"))]
29mod other {
30 use crate::transaction_git::GitContext;
31 use crate::worktree_add_plan::AddPlan;
32 use crate::worktree_copy::{GitRunner, GitStatus, GitStep};
33 use crate::worktree_identity::WorktreeIdentity;
34 use std::io::Write;
35 use std::path::PathBuf;
36
37 /// The ladder that does nothing.
38 pub struct Ladder;
39
40 /// What the ladder tells the lifecycle after Git.
41 pub struct LadderResult {
42 /// Git's status for the person.
43 pub git: GitStatus,
44 /// The destination that received the source's ignored state with the snapshot.
45 pub carried: Option<PathBuf>,
46 }
47
48 /// Prepare nothing.
49 pub fn begin_ladder(_plan: Option<&AddPlan>, _context: &GitContext, _identity: &WorktreeIdentity) -> Ladder {
50 return Ladder;
51 }
52
53 impl Ladder {
54 /// The person's arguments.
55 pub fn first_step(&self) -> GitStep<'static> {
56 return GitStep::Person;
57 }
58
59 /// Settle nothing.
60 pub fn finish(self, git: GitStatus, __run_git: &mut GitRunner, _context: &GitContext, _out: &mut dyn Write) -> LadderResult {
61 return LadderResult { git, carried: None };
62 }
63 }
64}
65
66#[cfg(not(target_os = "linux"))]
67pub use other::{Ladder, LadderResult, begin_ladder};