Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Git/
HandleClone.rs

1//! `localGit:clone(operationId, cloneUrl, targetPath, ref?)`.
2//! Optional `ref` becomes `--branch <ref>` so callers can
3//! shallow-clone a tag or branch.
4
5use serde_json::Value;
6
7use crate::IPC::WindServiceHandlers::{Git::Shared::RunGit::Fn as RunGit, Utilities::JsonValueHelpers::arg_string};
8
9pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
10	let OperationId = arg_string(&Arguments, 0);
11
12	let CloneURL = arg_string(&Arguments, 1);
13
14	let TargetPath = arg_string(&Arguments, 2);
15
16	let Reference = Arguments.get(3).and_then(Value::as_str).map(str::to_string);
17
18	if CloneURL.is_empty() || TargetPath.is_empty() {
19		return Err("git:clone requires cloneUrl and targetPath".to_string());
20	}
21
22	let mut Argv:Vec<String> = vec!["clone".to_string()];
23
24	if let Some(Ref) = Reference {
25		Argv.push("--branch".to_string());
26
27		Argv.push(Ref);
28	}
29
30	Argv.push("--".to_string());
31
32	Argv.push(CloneURL);
33
34	Argv.push(TargetPath);
35
36	let (ExitCode, _, Stderr) = RunGit(&OperationId, &Argv, None).await?;
37
38	if ExitCode != 0 {
39		return Err(format!("git clone failed: {}", Stderr));
40	}
41
42	Ok(Value::Null)
43}