on master help sign in
Check for 'git' before fetching/building grammars (#7320)

Previously the error message for this potential failure-case was confusing: "no such file or directory". `hx -g fetch`, `hx -g build` and the helix-term builder should bail early if the git binary is not available.

commit25ad534d6404e2aa39536df818371dcbbc928b52 authorMichael Davis <mcarsondavis@gmail.com> dateMon 12 Jun 2023, 10:32 (3 years ago) parent18e07ad
3 files changed+13
Cargo.lock+1 helix-loader/Cargo.toml+1 helix-loader/src/grammar.rs+11
Cargo.lock+1
@@ -1167,6 +1167,7 @@ dependencies = [
11671167 "threadpool",
11681168 "toml",
11691169 "tree-sitter",
1170+ "which",
11701171]
11711172
11721173[[package]]
helix-loader/Cargo.toml+1
@@ -21,6 +21,7 @@ etcetera = "0.8"
2121tree-sitter = "0.20"
2222once_cell = "1.18"
2323log = "0.4"
24+which = "4.4"
2425
2526# TODO: these two should be on !wasm32 only
2627
helix-loader/src/grammar.rs+11
@@ -85,7 +85,16 @@ pub fn get_language(name: &str) -> Result<Language> {
8585 Ok(language)
8686}
8787
88+fn ensure_git_is_available() -> Result<()> {
89+ match which::which("git") {
90+ Ok(_cmd) => Ok(()),
91+ Err(err) => Err(anyhow::anyhow!("'git' could not be found ({err})")),
92+ }
93+}
94+
8895pub fn fetch_grammars() -> Result<()> {
96+ ensure_git_is_available()?;
97+
8998 // We do not need to fetch local grammars.
9099 let mut grammars = get_grammar_configs()?;
91100 grammars.retain(|grammar| !matches!(grammar.source, GrammarSource::Local { .. }));
@@ -145,6 +154,8 @@ pub fn fetch_grammars() -> Result<()> {
145154}
146155
147156pub fn build_grammars(target: Option<String>) -> Result<()> {
157+ ensure_git_is_available()?;
158+
148159 let grammars = get_grammar_configs()?;
149160 println!("Building {} grammars", grammars.len());
150161 let results = run_parallel(grammars, move |grammar| {