on master help sign in
Check for 'git' before fetching/building grammars (#7320)
25ad534Michael Davis
Cargo.lock+1
@@ -1167,6 +1167,7 @@ dependencies = [
1167 "threadpool",
1167 "threadpool",
1168 "toml",
1168 "toml",
1169 "tree-sitter",
1169 "tree-sitter",
1170+ "which",
1170]
1171]
1171
1172
1172[[package]]
1173[[package]]
helix-loader/Cargo.toml+1
@@ -21,6 +21,7 @@ etcetera = "0.8"
21tree-sitter = "0.20"
21tree-sitter = "0.20"
22once_cell = "1.18"
22once_cell = "1.18"
23log = "0.4"
23log = "0.4"
24+which = "4.4"
24
25
25# TODO: these two should be on !wasm32 only
26# TODO: these two should be on !wasm32 only
26
27
helix-loader/src/grammar.rs+11
@@ -85,7 +85,16 @@ pub fn get_language(name: &str) -> Result<Language> {
85 Ok(language)
85 Ok(language)
86}
86}
87
87
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+
88pub fn fetch_grammars() -> Result<()> {
95pub fn fetch_grammars() -> Result<()> {
96+ ensure_git_is_available()?;
97+
89 // We do not need to fetch local grammars.
98 // We do not need to fetch local grammars.
90 let mut grammars = get_grammar_configs()?;
99 let mut grammars = get_grammar_configs()?;
91 grammars.retain(|grammar| !matches!(grammar.source, GrammarSource::Local { .. }));
100 grammars.retain(|grammar| !matches!(grammar.source, GrammarSource::Local { .. }));
@@ -145,6 +154,8 @@ pub fn fetch_grammars() -> Result<()> {
145}
154}
146
155
147pub fn build_grammars(target: Option<String>) -> Result<()> {
156pub fn build_grammars(target: Option<String>) -> Result<()> {
157+ ensure_git_is_available()?;
158+
148 let grammars = get_grammar_configs()?;
159 let grammars = get_grammar_configs()?;
149 println!("Building {} grammars", grammars.len());
160 println!("Building {} grammars", grammars.len());
150 let results = run_parallel(grammars, move |grammar| {
161 let results = run_parallel(grammars, move |grammar| {