Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleIsAvailable.rs

1
2//! `localGit:isAvailable -> bool`. Cheap `git --version` probe
3//! cached in a `OnceLock` for the process lifetime so the UI's
4//! periodic poll doesn't re-exec git every interval.
5
6use std::sync::OnceLock;
7
8use serde_json::{Value, json};
9use tokio::process::Command;
10
11use crate::dev_log;
12
13pub async fn Fn(_Arguments:Vec<Value>) -> Result<Value, String> {
14	// Cache only a `true` result - once git is confirmed available it stays
15	// available for the process lifetime.  A `false` result is NOT cached:
16	// the first probe may run before EnhanceShellEnvironment has extended
17	// PATH, so a transient miss must not permanently disable the SCM UI.
18	static CACHE:OnceLock<bool> = OnceLock::new();
19
20	if CACHE.get() == Some(&true) {
21		return Ok(json!(true));
22	}
23
24	let Available = Command::new("git")
25		.arg("--version")
26		.output()
27		.await
28		.map(|O| O.status.success())
29		.unwrap_or(false);
30
31	if Available {
32		let _ = CACHE.set(true);
33	}
34
35	dev_log!("git", "[Git] isAvailable={}", Available);
36
37	Ok(json!(Available))
38}