#![allow(clippy::missing_panics_doc, clippy::must_use_candidate)]
use std::path::Path;
use std::process::Command;
const MOMENT: &str = "1700000000 +0000";
#[cfg(windows)]
const NULL_DEVICE: &str = "NUL";
#[cfg(not(windows))]
const NULL_DEVICE: &str = "/dev/null";
pub const ISOLATION: [(&str, &str); 2] = [
("GIT_CONFIG_NOSYSTEM", "1"),
("GIT_CONFIG_GLOBAL", NULL_DEVICE),
];
pub fn command() -> Command {
let mut command = Command::new("git");
command
.envs(ISOLATION)
.env("GIT_AUTHOR_DATE", MOMENT)
.env("GIT_COMMITTER_DATE", MOMENT)
.args(["-c", "user.name=test", "-c", "user.email=test@example.com"])
.args(["-c", "commit.gpgSign=false"]);
command
}
pub fn git(dir: &Path, args: &[&str]) -> String {
let output = command()
.args(args)
.current_dir(dir)
.output()
.expect("git runs");
assert!(
output.status.success(),
"git {args:?}: {}",
String::from_utf8_lossy(&output.stderr)
);
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
pub fn succeeds(dir: &Path, args: &[&str]) -> bool {
command()
.args(args)
.current_dir(dir)
.output()
.expect("git runs")
.status
.success()
}