OXYGENHUB
◆ main oxygen / tests / cli_subrepo.rs
3.1 KiB · Rust · last changed Name moved subrepo pins in status and commit; changelog on the WASM tier (closes #162) 22 hours ago source blame history raw
1
//! oxygen#162: a subrepo pin moved by work inside the subrepo is a change
2
//! the parent's next commit records; `oxy status` and `oxy commit` say so,
3
//! and say when a subrepo holds uncommitted edits of its own.
4
5
use std::path::Path;
6
use std::process::Command;
7
8
fn oxy(dir: &Path, home: &Path, args: &[&str]) -> (i32, String) {
9
    let out = Command::new(env!("CARGO_BIN_EXE_oxy"))
10
        .arg("--plain")
11
        .args(args)
12
        .current_dir(dir)
13
        .env("OXY_HOME", home)
14
        .env("NO_COLOR", "1")
15
        .output()
16
        .unwrap();
17
    let text = format!(
18
        "{}{}",
19
        String::from_utf8_lossy(&out.stdout),
20
        String::from_utf8_lossy(&out.stderr)
21
    );
22
    (out.status.code().unwrap_or(-1), text)
23
}
24
25
fn ok(dir: &Path, home: &Path, args: &[&str]) -> String {
26
    let (code, out) = oxy(dir, home, args);
27
    assert_eq!(code, 0, "oxy {args:?}: {out}");
28
    out
29
}
30
31
#[test]
32
fn moved_pins_and_edits_inside_subrepos_are_named() {
33
    let tmp = tempfile::tempdir().unwrap();
34
    let t = tmp.path();
35
    let home = t.join("home");
36
    std::fs::create_dir_all(&home).unwrap();
37
    ok(
38
        t,
39
        &home,
40
        &[
41
            "identity",
42
            "create",
43
            "--name",
44
            "Ada",
45
            "--email",
46
            "[email protected]",
47
        ],
48
    );
49
    // The subrepo's own repository, with one change.
50
    let lib = t.join("lib");
51
    ok(t, &home, &["init", lib.to_str().unwrap()]);
52
    std::fs::write(lib.join("lib.txt"), "one\n").unwrap();
53
    ok(&lib, &home, &["commit", "-m", "lib one"]);
54
    // The parent pins it.
55
    let app = t.join("app");
56
    ok(t, &home, &["init", app.to_str().unwrap()]);
57
    std::fs::write(app.join("app.txt"), "app\n").unwrap();
58
    ok(
59
        &app,
60
        &home,
61
        &["submodule", "add", lib.to_str().unwrap(), "deps/lib"],
62
    );
63
    ok(&app, &home, &["commit", "-m", "app with lib"]);
64
    let quiet = ok(&app, &home, &["status"]);
65
    assert!(!quiet.contains("Subrepo pins"), "{quiet}");
66
67
    // Edits inside the subrepo, not committed there: named, not a pin move.
68
    let inner = app.join("deps/lib");
69
    std::fs::write(inner.join("lib.txt"), "two\n").unwrap();
70
    let st = ok(&app, &home, &["status"]);
71
    assert!(
72
        st.contains("Subrepo pins") && st.contains("uncommitted edits inside it"),
73
        "{st}"
74
    );
75
    assert!(!st.contains("pin moved"), "{st}");
76
77
    // Committed inside: the pin has moved, and a bare commit says it records it.
78
    ok(&inner, &home, &["commit", "-m", "lib two"]);
79
    let st = ok(&app, &home, &["status"]);
80
    assert!(st.contains("deps/lib") && st.contains("pin moved"), "{st}");
81
    std::fs::write(app.join("app.txt"), "app 2\n").unwrap();
82
    let by_path = ok(&app, &home, &["commit", "-m", "app only", "app.txt"]);
83
    assert!(
84
        !by_path.contains("recorded subrepo"),
85
        "a commit by path leaves the pin out: {by_path}"
86
    );
87
    let bare = ok(&app, &home, &["commit", "-m", "everything"]);
88
    assert!(
89
        bare.contains("recorded subrepo deps/lib's pin moving") && bare.contains("a pin bump"),
90
        "{bare}"
91
    );
92
    let after = ok(&app, &home, &["status"]);
93
    assert!(!after.contains("Subrepo pins"), "recorded: {after}");
94
}