Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleCheckout.rs

1
2//! `localGit:checkout(operationId, repoPath, treeish, detached?)`.
3//! `Detached=true` adds `--detach` so the caller can land on a
4//! commit hash without creating a tracking branch.
5
6use serde_json::Value;
7
8use crate::IPC::WindServiceHandlers::Git::Shared::RunGit::Fn as RunGit;
9
10pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
11	let OperationId = Arguments.first().and_then(Value::as_str).unwrap_or("").to_string();
12
13	let RepoPath = Arguments.get(1).and_then(Value::as_str).unwrap_or("").to_string();
14
15	let Treeish = Arguments.get(2).and_then(Value::as_str).unwrap_or("").to_string();
16
17	let Detached = Arguments.get(3).and_then(Value::as_bool).unwrap_or(false);
18
19	if RepoPath.is_empty() || Treeish.is_empty() {
20		return Err("git:checkout requires repoPath and treeish".to_string());
21	}
22
23	let Argv:Vec<String> = if Detached {
24		vec!["checkout".to_string(), "--detach".to_string(), Treeish]
25	} else {
26		vec!["checkout".to_string(), Treeish]
27	};
28
29	let (ExitCode, _, Stderr) = RunGit(&OperationId, &Argv, Some(&RepoPath)).await?;
30
31	if ExitCode != 0 {
32		return Err(format!("git checkout failed: {}", Stderr));
33	}
34
35	Ok(Value::Null)
36}