croft-software 0.2.232

VSCode-style TUI written in Rust
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
//! Every git call the git module makes, recorded (#2062, card 12).
//!
//! One scenario drives each of the module's entry points against a fixture
//! repository, with `git` replaced by a stand-in that writes down what croft
//! handed it and then runs the real git. The record is saved in
//! `src/app/tests/golden/git-calls.txt`. A change to how croft starts git
//! must leave it byte-identical, unless the change is meant to move a call,
//! which `CROFT_BLESS=1` then writes down.
//!
//! The real git runs shut off from the developer's own setup (no global or
//! system config) and with one fixed date and identity, so every commit, and
//! every hash an argument carries, is the same on every machine.

#![cfg(target_os = "linux")]

use super::*;
use crate::test_git::test_git;
use std::path::{Path, PathBuf};

const SAVED: &str = concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/src/app/tests/golden/git-calls.txt"
);

/// The date of every commit, in the fixture and made by croft.
const DATE: &str = "2099-01-01T00:00:00Z";

/// git for building the fixture, outside the recording.
fn fixture(dir: &Path, args: &[&str]) -> String {
    let out = test_git(dir)
        .args(args)
        .env("GIT_AUTHOR_DATE", DATE)
        .env("GIT_COMMITTER_DATE", DATE)
        .output()
        .unwrap();
    assert!(
        out.status.success(),
        "fixture git {args:?}: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    String::from_utf8_lossy(&out.stdout).trim().to_string()
}

fn write(path: &Path, text: &str) {
    if let Some(parent) = path.parent() {
        std::fs::create_dir_all(parent).unwrap();
    }
    std::fs::write(path, text).unwrap();
}

/// The record so far, one titled section per step.
struct Script {
    recording: crate::proc::record::Recording,
    names: Vec<(PathBuf, &'static str)>,
    out: String,
}

impl Script {
    /// Write down, under `title`, every git run since the last step.
    fn step(&mut self, title: &str) {
        let names: Vec<(&Path, &str)> = self
            .names
            .iter()
            .map(|(path, name)| (path.as_path(), *name))
            .collect();
        let runs = self.recording.take(&names);
        self.out.push_str(&format!("## {title}\n"));
        for run in runs {
            self.out.push_str(&run);
            self.out.push('\n');
        }
    }
}

/// The variable that names where [`child_records_every_git_call`] writes
/// its record; the test does nothing without it.
const RECORD_TO: &str = "CROFT_RECORD_GIT_CALLS_TO";

/// Variables croft might set for git or take away from it, each given
/// [`SEEDED_VALUE`] in the scenario's environment: a call that removes one
/// shows the removal, and one that sets it shows its own value. With the
/// variable absent, taking it away would leave no trace in the record.
const SEEDED: [&str; 12] = [
    "GIT_DIR",
    "GIT_WORK_TREE",
    "GIT_INDEX_FILE",
    "GIT_COMMON_DIR",
    "GIT_OBJECT_DIRECTORY",
    "GIT_TERMINAL_PROMPT",
    "GIT_OPTIONAL_LOCKS",
    "GIT_EDITOR",
    "GIT_SEQUENCE_EDITOR",
    "GIT_PAGER",
    "GIT_ASKPASS",
    "LANGUAGE",
];

/// The value every [`SEEDED`] variable starts with. The stand-in takes it
/// away again before the real git runs, keeping any value croft set.
const SEEDED_VALUE: &str = "croft-recorded-seed";

/// The scenario runs in a fresh copy of this test binary with an empty
/// environment but `PATH`, a scratch `HOME` and the [`SEEDED`] variables. Run here, a variable the
/// machine already sets, as a CI runner or a sandbox does
/// (`GIT_TERMINAL_PROMPT`, `GIT_EDITOR`, `LANGUAGE`), hides croft setting the
/// same value, so the record would differ from machine to machine.
#[test]
fn every_git_call_is_made_as_recorded() {
    let home = tempfile::tempdir().unwrap();
    let record = home.path().join("git-calls.txt");
    let out = std::process::Command::new(std::env::current_exe().unwrap())
        .args([
            "git::recorded_calls::child_records_every_git_call",
            "--exact",
            "--test-threads=1",
            "--nocapture",
        ])
        .env_clear()
        .env("PATH", std::env::var_os("PATH").unwrap_or_default())
        .env("HOME", home.path())
        .envs(SEEDED.map(|name| (name, SEEDED_VALUE)))
        .env(RECORD_TO, &record)
        .output()
        .unwrap();
    let log = format!(
        "{}{}",
        String::from_utf8_lossy(&out.stdout),
        String::from_utf8_lossy(&out.stderr)
    );
    assert!(out.status.success(), "the recording failed:\n{log}");
    assert!(
        log.contains("1 passed"),
        "the recording did not run:\n{log}"
    );
    let now = std::fs::read_to_string(&record).unwrap();
    crate::proc::record::check_saved(Path::new(SAVED), &now);
}

/// The scenario, run by [`every_git_call_is_made_as_recorded`].
#[test]
fn child_records_every_git_call() {
    let Some(record_to) = std::env::var_os(RECORD_TO) else {
        return;
    };
    let tmp = tempfile::tempdir().unwrap();
    let tmp = tmp.path().canonicalize().unwrap();
    let bin = tmp.join("bin");
    std::fs::create_dir(&bin).unwrap();
    let repo = tmp.join("repo");
    let origin = tmp.join("origin.git");
    std::fs::create_dir(&repo).unwrap();

    // The fixture: main with two commits and a tag on the first, a
    // `feature` branch off the first, and a bare `origin` both are pushed to.
    fixture(&tmp, &["init", "-q", "--bare", "-b", "main", "origin.git"]);
    fixture(&repo, &["init", "-q", "-b", "main"]);
    write(&repo.join("a.txt"), "one\n");
    write(&repo.join("b.txt"), "two\n");
    write(&repo.join("dir/c.txt"), "three\n");
    fixture(&repo, &["add", "-A"]);
    fixture(&repo, &["commit", "-q", "-m", "first"]);
    let first = fixture(&repo, &["rev-parse", "HEAD"]);
    fixture(&repo, &["tag", "v1"]);
    write(&repo.join("a.txt"), "one\nmore\n");
    fixture(&repo, &["commit", "-q", "-am", "second"]);
    let second = fixture(&repo, &["rev-parse", "HEAD"]);
    fixture(&repo, &["checkout", "-q", "-b", "feature", &first]);
    write(&repo.join("b.txt"), "two\nfeature\n");
    fixture(&repo, &["commit", "-q", "-am", "feature work"]);
    let feature = fixture(&repo, &["rev-parse", "HEAD"]);
    fixture(&repo, &["checkout", "-q", "main"]);
    fixture(
        &repo,
        &["remote", "add", "origin", &origin.display().to_string()],
    );
    fixture(&repo, &["push", "-q", "-u", "origin", "main", "feature"]);

    let real = crate::proc::record::real_program("git");
    let then = format!(
        "for v in {}; do eval \"[ \\\"\\${{$v-}}\\\" = {SEEDED_VALUE} ] && unset $v\"; done\n\
         exec env -u GIT_CONFIG_PARAMETERS -u GIT_CONFIG_COUNT \
         GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 XDG_CONFIG_HOME=/dev/null \
         GIT_AUTHOR_NAME=a GIT_AUTHOR_EMAIL=a@b GIT_COMMITTER_NAME=a GIT_COMMITTER_EMAIL=a@b \
         GIT_AUTHOR_DATE={DATE} GIT_COMMITTER_DATE={DATE} '{}' \"$@\"",
        SEEDED.join(" "),
        real.display()
    );
    let mut s = Script {
        recording: crate::proc::record::record(&bin, "git", &then),
        names: vec![
            (repo.clone(), "<repo>"),
            (origin.clone(), "<origin>"),
            (tmp.clone(), "<tmp>"),
        ],
        out: String::from(
            "# Every git call the git module makes: src/git/recorded_calls.rs. \
             Rewrite with CROFT_BLESS=1 after a change meant to move one.\n",
        ),
    };
    let rel = |paths: &[&str]| -> Vec<String> { paths.iter().map(|p| p.to_string()).collect() };

    // Status.
    let _ = repo_toplevel(&repo.join("dir"));
    s.step("repo_toplevel");
    let _ = query(&repo);
    s.step("status::query");
    let _ = query_changes(&repo);
    s.step("query_changes");
    let _ = is_ignored(&repo, &repo.join("a.txt"));
    s.step("is_ignored");
    let _ = child_repos(&tmp);
    s.step("child_repos");
    let _ = worktree_fingerprint(&repo);
    s.step("worktree_fingerprint");
    let _ = current_branch(&repo);
    s.step("current_branch");
    let _ = head_is_on_upstream(&repo);
    s.step("head_is_on_upstream");
    let _ = unpublished_branch(&repo);
    s.step("unpublished_branch");
    let _ = repo_operation(&repo);
    s.step("repo_operation");

    // Diffs and file contents, with a staged and an unstaged change.
    write(&repo.join("b.txt"), "two\nstaged\n");
    fixture(&repo, &["add", "b.txt"]);
    write(&repo.join("a.txt"), "one\nmore\nunstaged\n");
    let _ = diff_staged(&repo);
    s.step("diff_staged");
    let _ = merge_base(&repo, "feature");
    s.step("merge_base");
    let _ = diff_against_branch(&repo, "feature");
    s.step("diff_against_branch");
    let _ = diff_previous_commit(&repo);
    s.step("diff_previous_commit");
    let _ = is_submodule(&repo, "a.txt");
    s.step("is_submodule");
    let _ = submodule_diff(&repo, "a.txt");
    s.step("submodule_diff");
    let _ = contents::path_filter(&repo, "a.txt");
    s.step("path_filter");
    let _ = read_file_at_head(&repo, "a.txt");
    s.step("read_file_at_head");
    let _ = read_bytes_at_head(&repo, "a.txt");
    s.step("read_bytes_at_head");
    let _ = read_file_at_rev(&repo, "v1", "a.txt");
    s.step("read_file_at_rev");
    let _ = read_file_at_stage(&repo, "a.txt", 2);
    s.step("read_file_at_stage");
    let _ = remerge_diff3(&repo, "a.txt");
    s.step("remerge_diff3");
    let _ = query(&repo);
    s.step("status::query with changes");
    let _ = query_changes(&repo);
    s.step("query_changes with changes");

    // History and blame.
    let _ = file_history(&repo, "a.txt", 10);
    s.step("file_history");
    let _ = show_commit_file_diff(&repo, &second, "a.txt");
    s.step("show_commit_file_diff");
    let _ = follow_names(&repo, "a.txt", 10);
    s.step("follow_names");
    let _ = show_commit(&repo, &second);
    s.step("show_commit");
    let _ = commit_graph(&repo, 50);
    s.step("commit_graph");
    let _ = branch_history(&repo, 50);
    s.step("branch_history");
    let _ = branch_history_range(&repo, "main..feature", 50);
    s.step("branch_history_range");
    let _ = tree_paths(&repo, "HEAD");
    s.step("tree_paths");
    let _ = commit_message(&repo, &second);
    s.step("commit_message");
    let _ = commit_card(&repo, &second);
    s.step("commit_card");
    let _ = blame(&repo, "a.txt");
    s.step("blame");

    // A filtered file, as Git LFS keeps one: read through its filter, and
    // its commit diffed from the filtered sides.
    write(&repo.join(".gitattributes"), "*.dat filter=demo\n");
    fixture(&repo, &["config", "filter.demo.clean", "cat"]);
    fixture(&repo, &["config", "filter.demo.smudge", "cat"]);
    write(&repo.join("data.dat"), "filtered\n");
    fixture(&repo, &["add", ".gitattributes", "data.dat"]);
    fixture(
        &repo,
        &[
            "commit",
            "-q",
            "-m",
            "filtered",
            "--",
            ".gitattributes",
            "data.dat",
        ],
    );
    let filtered = fixture(&repo, &["rev-parse", "HEAD"]);
    let read = read_file_at_head(&repo, "data.dat");
    assert_eq!(read.as_deref(), Ok("filtered\n"));
    s.step("read_file_at_head of a filtered file");
    let read = read_file_at_rev(&repo, &filtered, "data.dat");
    assert_eq!(read.as_deref(), Ok("filtered\n"));
    s.step("read_file_at_rev of a filtered file");
    let diff = show_commit_file_diff(&repo, &filtered, "data.dat");
    assert!(
        diff.as_ref().is_ok_and(|d| d.contains("+filtered")),
        "{diff:?}"
    );
    s.step("show_commit_file_diff of a filtered file");

    // Staging and patches.
    write(&repo.join("d.txt"), "new\n");
    let _ = stage_path(&repo, "a.txt");
    s.step("stage_path");
    let _ = unstage_path(&repo, "a.txt");
    s.step("unstage_path");
    let _ = stage_paths(&repo, &rel(&["a.txt", "d.txt"]));
    s.step("stage_paths");
    let _ = unstage_paths(&repo, &rel(&["a.txt", "d.txt"]));
    s.step("unstage_paths");
    let _ = discard_path(&repo, "d.txt", true, false);
    s.step("discard_path untracked");
    let _ = discard_path(&repo, "a.txt", false, false);
    s.step("discard_path");
    let _ = discard_path(&repo, "b.txt", false, true);
    s.step("discard_path staged");
    let patch = "diff --git a/a.txt b/a.txt\n--- a/a.txt\n+++ b/a.txt\n@@ -1,2 +1,3 @@\n one\n more\n+patched\n";
    let _ = apply_patch(&repo, patch, false, false);
    s.step("apply_patch");
    let _ = apply_patch(&repo, patch, true, false);
    s.step("apply_patch cached");
    let _ = apply_patch(&repo, patch, true, true);
    s.step("apply_patch cached reverse");
    let _ = stage_all(&repo);
    s.step("stage_all");
    let _ = unstage_all(&repo);
    s.step("unstage_all");

    // Commits.
    let _ = commit(&repo, "all of it");
    s.step("commit");
    write(&repo.join("a.txt"), "one\nmore\npatched\nstaged\n");
    fixture(&repo, &["add", "a.txt"]);
    let _ = commit_staged(&repo, "staged only");
    s.step("commit_staged");
    let _ = commit_amend(&repo, "staged, amended");
    s.step("commit_amend");
    let _ = commit_amend_no_edit(&repo);
    s.step("commit_amend_no_edit");
    let _ = undo_last_commit(&repo);
    s.step("undo_last_commit");
    let _ = unmerged_paths(&repo);
    s.step("unmerged_paths");
    let _ = refuse_unmerged(&repo);
    s.step("refuse_unmerged");
    let _ = discard_all_tracked(&repo);
    s.step("discard_all_tracked");
    let _ = cherry_pick(&repo, &feature);
    s.step("cherry_pick");
    let _ = revert_commit(&repo, &second);
    s.step("revert_commit");
    let _ = create_tag_at(&repo, "t2", &first);
    s.step("create_tag_at");
    let _ = checkout_detached(&repo, &first);
    s.step("checkout_detached");
    let _ = checkout_branch(&repo, "main");
    s.step("checkout_branch");
    let _ = reset_to(&repo, &second, ResetMode::Mixed);
    s.step("reset_to mixed");
    let _ = reset_to(&repo, &second, ResetMode::Hard);
    s.step("reset_to hard");
    let _ = remove_path(&repo, "dir/c.txt");
    s.step("remove_path");
    fixture(&repo, &["reset", "-q", "--hard", "HEAD"]);

    // Branches.
    let _ = default_branch(&repo);
    s.step("default_branch");
    let _ = list_branches(&repo);
    s.step("list_branches");
    let _ = create_branch(&repo, "topic");
    s.step("create_branch");
    let _ = rename_branch(&repo, "topic-renamed");
    s.step("rename_branch");
    let _ = checkout_branch(&repo, "main");
    s.step("checkout_branch back");
    let _ = create_branch_from(&repo, "from-v1", "v1");
    s.step("create_branch_from");
    let _ = checkout_branch(&repo, "main");
    s.step("checkout_branch main");
    let _ = track_remote_branch(&repo, "origin/feature", "feature-local");
    s.step("track_remote_branch");
    let _ = checkout_branch(&repo, "main");
    s.step("checkout_branch main again");
    let _ = delete_branch(&repo, "topic-renamed");
    s.step("delete_branch");
    let _ = merge_branch(&repo, "feature");
    s.step("merge_branch");
    let _ = rebase_branch(&repo, "feature");
    s.step("rebase_branch");
    fixture(&repo, &["reset", "-q", "--hard", &second]);

    // Tags.
    let _ = tag_remote(&repo);
    s.step("tag_remote");
    let _ = list_tags(&repo);
    s.step("list_tags");
    let _ = create_tag(&repo, "v2", Some("second release"));
    s.step("create_tag");
    let _ = push_tags(&repo, "origin");
    s.step("push_tags");
    let _ = list_remote_tags(&repo, "origin");
    s.step("list_remote_tags");
    let _ = delete_remote_tag(&repo, "origin", "v2");
    s.step("delete_remote_tag");
    let _ = delete_tag(&repo, "v2");
    s.step("delete_tag");

    // Stashes.
    write(&repo.join("a.txt"), "stashed\n");
    let _ = stash_push(&repo, Some("first stash"));
    s.step("stash_push");
    let _ = list_stashes(&repo);
    s.step("list_stashes");
    let _ = show_stash(&repo, 0);
    s.step("show_stash");
    let _ = stash_apply(&repo, 0);
    s.step("stash_apply");
    let oid = stash_oid(&repo, 0).unwrap_or_default();
    s.step("stash_oid");
    let _ = stash_drop_oid(&repo, &oid);
    s.step("stash_drop_oid");
    write(&repo.join("e.txt"), "untracked\n");
    let _ = stash_push_untracked(&repo, None);
    s.step("stash_push_untracked");
    let _ = stash_pop(&repo);
    s.step("stash_pop");
    fixture(&repo, &["add", "a.txt"]);
    let _ = stash_push_staged(&repo, Some("staged stash"));
    s.step("stash_push_staged");
    let _ = stash_pop_at(&repo, 0);
    s.step("stash_pop_at");
    let _ = stash_push(&repo, None);
    s.step("stash_push again");
    let oid = stash_oid(&repo, 0).unwrap_or_default();
    s.step("stash_oid again");
    let _ = stash_pop_oid(&repo, &oid);
    s.step("stash_pop_oid");
    fixture(&repo, &["reset", "-q", "--hard", "HEAD"]);
    fixture(&repo, &["clean", "-q", "-f"]);

    // Remotes.
    let _ = list_remotes(&repo);
    s.step("list_remotes");
    let _ = add_remote(&repo, "other", &origin.display().to_string());
    s.step("add_remote");
    let _ = remove_remote(&repo, "other");
    s.step("remove_remote");
    let _ = fetch_all(&repo);
    s.step("fetch_all");
    write(&repo.join("a.txt"), "one\nmore\npushed\n");
    fixture(&repo, &["commit", "-q", "-am", "to push"]);
    let _ = push_current_branch(&repo);
    s.step("push_current_branch");
    let _ = pull_current_branch(&repo);
    s.step("pull_current_branch");
    let _ = pull_rebase(&repo);
    s.step("pull_rebase");
    let _ = push_force(&repo);
    s.step("push_force");
    let _ = push_to_remote(&repo, "origin");
    s.step("push_to_remote");
    fixture(&repo, &["checkout", "-q", "-b", "unpushed"]);
    let _ = unpublished_branch(&repo);
    s.step("unpublished_branch on a new branch");
    let _ = push_or_publish(&repo);
    s.step("push_or_publish");
    fixture(&repo, &["checkout", "-q", "-b", "to-publish"]);
    let _ = publish_branch(&repo, "to-publish");
    s.step("publish_branch");
    fixture(&repo, &["checkout", "-q", "main"]);
    let _ = clone_into(&tmp, &origin.display().to_string());
    s.step("clone_into");
    // A web link needs a GitHub-style remote; main is pushed, so both the
    // commit and the branch are on it, and no network is used.
    let local_origin = origin.display().to_string();
    fixture(
        &repo,
        &[
            "remote",
            "set-url",
            "origin",
            "https://github.com/owner/repo.git",
        ],
    );
    let link = share_link(&repo.join("a.txt"), Some((1, 2)), LinkRev::Commit);
    assert!(link.is_ok(), "{link:?}");
    s.step("share_link commit");
    let link = share_link(&repo.join("a.txt"), None, LinkRev::Branch);
    assert!(link.is_ok(), "{link:?}");
    s.step("share_link branch");
    fixture(&repo, &["remote", "set-url", "origin", &local_origin]);

    // Worktrees.
    let mut lane = worktrees::WorktreeLane::plan(&repo, "lane one").unwrap();
    let _ = add_worktree_lane(&repo, &mut lane);
    s.step("add_worktree_lane");
    let _ = lane_removal_block(&lane.path);
    s.step("lane_removal_block");
    let _ = worktrees::worktree_head(&lane.path);
    s.step("worktree_head");
    let _ = pr_worktree_keep_reason(&lane.path, "main");
    s.step("pr_worktree_keep_reason");
    let _ = remove_worktree_lane(&lane.path);
    s.step("remove_worktree_lane");
    let _ = pr_worktree_path(&repo, 7);
    s.step("pr_worktree_path");
    let _ = remote_for_slug(&repo, "owner/repo");
    s.step("remote_for_slug");
    // A pull request's head, as GitHub keeps one: checked out into a new
    // worktree, then moved on when the pull request moves.
    let pr = tmp.join("pr-7");
    fixture(&origin, &["update-ref", "refs/pull/7/head", &feature]);
    let made = checkout_pr_worktree(&repo, "origin", 7, &pr, None);
    assert!(made.as_ref().is_ok_and(|w| w.created), "{made:?}");
    s.step("checkout_pr_worktree");
    fixture(&origin, &["update-ref", "refs/pull/7/head", &second]);
    let moved = checkout_pr_worktree(&repo, "origin", 7, &pr, Some(&feature));
    assert!(moved.as_ref().is_ok_and(|w| !w.created), "{moved:?}");
    s.step("checkout_pr_worktree when the pull request moved");

    // Operations in progress: a merge that conflicts, aborted; a
    // cherry-pick that conflicts, resolved and continued; one skipped; then
    // a bisect, reset.
    fixture(&repo, &["checkout", "-q", "-b", "clash", &first]);
    write(&repo.join("a.txt"), "clash\n");
    fixture(&repo, &["commit", "-q", "-am", "clash"]);
    let clash = fixture(&repo, &["rev-parse", "HEAD"]);
    fixture(&repo, &["checkout", "-q", "main"]);
    let _ = merge_branch(&repo, "clash");
    s.step("merge_branch that conflicts");
    let _ = repo_operation(&repo);
    s.step("repo_operation during a merge");
    let _ = unmerged_paths(&repo);
    s.step("unmerged_paths during a merge");
    let _ = read_file_at_stage(&repo, "a.txt", 3);
    s.step("read_file_at_stage during a merge");
    let _ = remerge_diff3(&repo, "a.txt");
    s.step("remerge_diff3 during a merge");
    let _ = refuse_unmerged(&repo);
    s.step("refuse_unmerged during a merge");
    let _ = stage_path(&repo, "a.txt");
    s.step("stage_path with conflict markers");
    let _ = continue_operation(&repo, RepoOp::Merge);
    s.step("continue_operation of a merge");
    let _ = abort_operation(&repo, RepoOp::Merge);
    s.step("abort_operation of a merge");

    let _ = cherry_pick(&repo, &clash);
    s.step("cherry_pick that conflicts");
    let _ = repo_operation(&repo);
    s.step("repo_operation during a cherry-pick");
    write(&repo.join("a.txt"), "resolved\n");
    fixture(&repo, &["add", "a.txt"]);
    let _ = continue_operation(&repo, RepoOp::CherryPick);
    s.step("continue_operation of a cherry-pick");
    fixture(&repo, &["reset", "-q", "--hard", "HEAD~1"]);
    let _ = cherry_pick(&repo, &clash);
    s.step("cherry_pick that conflicts again");
    let _ = skip_operation(&repo, RepoOp::CherryPick);
    s.step("skip_operation of a cherry-pick");

    fixture(&repo, &["bisect", "start", "HEAD", &first]);
    let _ = bisect_mark(&repo, true);
    s.step("bisect_mark good");
    let _ = bisect_mark(&repo, false);
    s.step("bisect_mark bad");
    let _ = repo_operation(&repo);
    s.step("repo_operation during a bisect");
    let _ = abort_operation(&repo, RepoOp::Bisect);
    s.step("abort_operation of a bisect");

    std::fs::write(record_to, &s.out).unwrap();
}