Skip to main content

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::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) = RunGit(
23		&uuid::Uuid::new_v4().to_string(),
24		&["rev-parse".to_string(), Reference],
25		Some(&RepoPath),
26	)
27	.await?;
28
29	if ExitCode != 0 {
30		return Err(format!("git rev-parse failed: {}", Stderr));
31	}
32
33	Ok(json!(Stdout.trim()))
34}