Improve error when git not installed

This commit is contained in:
Damien Elmes 2025-01-10 21:05:34 +11:00
parent b189820218
commit 3bdf61e2fd

View file

@ -7,6 +7,8 @@ use std::io::Write;
use std::process::Command; use std::process::Command;
use std::time::Instant; use std::time::Instant;
use anki_process::CommandExt;
use anyhow::Context;
use camino::Utf8Path; use camino::Utf8Path;
use camino::Utf8PathBuf; use camino::Utf8PathBuf;
use clap::Args; use clap::Args;
@ -162,11 +164,12 @@ fn maybe_update_buildhash(build_root: &Utf8Path) {
fn get_buildhash() -> String { fn get_buildhash() -> String {
let output = Command::new("git") let output = Command::new("git")
.args(["rev-parse", "--short=8", "HEAD"]) .args(["rev-parse", "--short=8", "HEAD"])
.output() .utf8_output()
.expect("git"); .context(
assert!(output.status.success(), "Make sure you're building from a clone of the git repo, and that 'git' is installed.",
"Invoking 'git' failed. Make sure you're building from a clone of the git repo, and that 'git' is installed."); )
String::from_utf8(output.stdout).unwrap().trim().into() .unwrap();
output.stdout.trim().into()
} }
fn write_if_changed(path: &Utf8Path, contents: &str) { fn write_if_changed(path: &Utf8Path, contents: &str) {