Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleRevParse.rs

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