1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! The transient authoring checkout and its teardown (ARCH §2.2).
//!
//! Both config-commit authoring acts — [`super::scaffold`] for a
//! workspace's first commit, [`super::authoring::author`] for every later
//! one — materialize one checkout at `<workspace>/.config-author`, edit
//! it, commit, and tear it down. This module owns the teardown so it
//! **cannot be skipped**: [`Checkout`] is a drop guard, so the decline, a
//! git failure, an editor failure and an early `?` all tear down by the
//! same path the success case does. Anything a *killed* pass leaves
//! behind is cleared by [`heal`] at the next pass's start — ARCH §2.11's
//! crash philosophy ("everything is on disk … the next touch heals it")
//! applied to this checkout, so a hard kill never wedges the verb behind
//! a hand-run `git worktree remove`.
use GitRunner;
use fs;
use io;
use ;
/// Transient authoring checkout under the workspace root; removed once
/// the pass ends, however it ends. One at a time — authoring a config
/// commit is a deliberate single-user act (ARCH §1.1).
const AUTHOR_DIR: &str = ".config-author";
/// The authoring checkout's path inside `workspace`.
pub
/// Clear the checkout path so a pass can materialize on it, whatever an
/// interrupted predecessor left (ARCH §2.11): a stale registration whose
/// directory is gone is git's own `prune`, and a surviving directory is
/// debris this removes. Unconditional — on the ordinary path there is
/// nothing there and every step is a no-op, so there is no leftover
/// special case to get wrong, and no state a hard kill can leave that
/// makes the *next* `lernie config` fail. The transient checkout holds no
/// authored history by construction (its content is the origin's tree
/// plus the pools plus an uncommitted edit), so removing it loses only
/// the killed pass's unsaved edit. A path that survives all three steps
/// surfaces as an error rather than a silent wedge.
pub
/// A materialized authoring checkout, torn down when it drops.
///
/// Construction is the `git worktree add`; teardown is [`Drop`], so every
/// exit path out of an authoring pass — including the ones that never
/// reach a commit — removes the checkout. `created` names the ref the add
/// itself created (`-b`, i.e. a fork or an orphan lineage); unless
/// [`Checkout::landed`] is called it is deleted along with the checkout,
/// so a failed or declined pass leaves no dangling `config/<name>`.
pub
/// `worktree remove` for `path`. `--force` because the failure paths tear
/// down a dirty checkout (an edit that was never committed), and the
/// success path's checkout is clean, where it changes nothing — one form
/// for both.