Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Git/
HandleIsAvailable.rs

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