Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleRevParse.rs

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