Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Git/
HandleRevParse.rs

1//! `localGit:revParse(repoPath, ref) -> string`. Defaults
2//! `ref=HEAD` so the caller can pass two args or three. Output
3//! is trimmed - `git rev-parse` ships a trailing newline that
4//! breaks string equality on the JS side.
5
6use serde_json::{Value, json};
7
8use crate::IPC::WindServiceHandlers::{
9	Git::Shared::{Generated::Fn as Generated, RunGit::Fn as RunGit},
10	Utilities::JsonValueHelpers::{arg_string, arg_string_or},
11};
12
13pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
14	let RepoPath = arg_string(&Arguments, 0);
15
16	let Reference = arg_string_or(&Arguments, 1, "HEAD");
17
18	if RepoPath.is_empty() {
19		return Err("git:revParse requires repoPath".to_string());
20	}
21
22	let (ExitCode, Stdout, Stderr) =
23		RunGit(&Generated(), &["rev-parse".to_string(), Reference], Some(&RepoPath)).await?;
24
25	if ExitCode != 0 {
26		return Err(format!("git rev-parse failed: {}", Stderr));
27	}
28
29	Ok(json!(Stdout.trim()))
30}