macro_rules! step {
($step:literal, $cond:expr $(,)?) => {
assert!($cond, "step `{}`: {}", $step, stringify!($cond))
};
($step:literal, $cond:expr, $($arg:tt)+) => {
assert!($cond, "step `{}`: {}", $step, format_args!($($arg)+))
};
}
macro_rules! step_eq {
($step:literal, $left:expr, $right:expr $(,)?) => {
assert_eq!($left, $right, "step `{}`", $step)
};
($step:literal, $left:expr, $right:expr, $($arg:tt)+) => {
assert_eq!($left, $right, "step `{}`: {}", $step, format_args!($($arg)+))
};
}
use crate::common::Repo;
use std::process::{Output, Stdio};
fn said(out: &Output) -> (bool, String) {
(
out.status.success(),
format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
),
)
}
fn amont(r: &Repo, args: &[&str]) -> (bool, String) {
let mut cmd = crate::common::amont_cmd();
cmd.args(args).current_dir(&r.dir).stdin(Stdio::null());
Repo::strip_git_env_impl(&mut cmd);
said(&cmd.output().expect("run amont"))
}
fn install(r: &Repo) {
for verb in ["trust", "init"] {
let (ok, out) = amont(r, &[verb]);
step!("install", ok, "amont {verb}:\n{out}");
}
}
fn git(r: &Repo, args: &[&str]) -> (bool, String) {
said(&r.git(args))
}
fn git_commit(r: &Repo, args: &[&str]) -> (bool, String) {
let mut all = vec!["commit", "-q"];
all.extend_from_slice(args);
git(r, &all)
}
fn read(r: &Repo, path: &str) -> String {
std::fs::read_to_string(r.path(path)).unwrap_or_else(|e| panic!("read {path}: {e}"))
}
fn git_out(r: &Repo, args: &[&str]) -> String {
String::from_utf8_lossy(&r.git(args).stdout)
.trim_end()
.to_string()
}
fn head(r: &Repo) -> String {
git_out(r, &["rev-parse", "HEAD"])
}
mod commit;
mod declared;
mod land;
mod onboarding;
mod push;