Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Git/
HandleIsAvailable.rs

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