DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/SCM/
GitExec.rs1use tonic::{Response, Status};
6
7use crate::{
8 RPC::CocoonService::CocoonServiceImpl,
9 Vine::Generated::{GitExecRequest, GitExecResponse},
10 dev_log,
11};
12
13pub async fn Fn(_Service:&CocoonServiceImpl, Request:GitExecRequest) -> Result<Response<GitExecResponse>, Status> {
14 dev_log!("cocoon", "[CocoonService] git_exec: {}", Request.args.join(" "));
15
16 dev_log!(
17 "git",
18 "[Git] exec-begin cwd={} args=[{}]",
19 if Request.repository_path.is_empty() {
20 "<cwd>".to_string()
21 } else {
22 Request.repository_path.clone()
23 },
24 Request.args.join(" ")
25 );
26
27 let WorkingDirectory = if Request.repository_path.is_empty() {
28 std::env::current_dir().unwrap_or_default()
29 } else {
30 std::path::PathBuf::from(&Request.repository_path)
31 };
32
33 let Output = tokio::process::Command::new("git")
34 .args(&Request.args)
35 .current_dir(&WorkingDirectory)
36 .output()
37 .await
38 .map_err(|Error| {
39 dev_log!("cocoon", "error: [CocoonService] git_exec failed to spawn: {}", Error);
40 dev_log!(
41 "git",
42 "[Git] exec-spawn-fail cwd={:?} args=[{}] error={}",
43 WorkingDirectory,
44 Request.args.join(" "),
45 Error
46 );
47 Status::internal(format!("git_exec: failed to spawn git: {}", Error))
48 })?;
49
50 let ExitCode = Output.status.code().unwrap_or(-1);
51
52 dev_log!(
53 "cocoon",
54 "[CocoonService] git_exec exit={} stdout={} bytes stderr={} bytes",
55 ExitCode,
56 Output.stdout.len(),
57 Output.stderr.len()
58 );
59
60 dev_log!(
61 "git",
62 "[Git] exec-done args=[{}] exit={} stdout={} stderr={}",
63 Request.args.join(" "),
64 ExitCode,
65 Output.stdout.len(),
66 Output.stderr.len()
67 );
68
69 let StdoutString = String::from_utf8_lossy(&Output.stdout);
70
71 let StderrString = String::from_utf8_lossy(&Output.stderr);
72
73 let mut OutputLines:Vec<String> = StdoutString.lines().map(|L| L.to_string()).collect();
74
75 for Line in StderrString.lines() {
76 OutputLines.push(format!("stderr: {}", Line));
77 }
78
79 Ok(Response::new(GitExecResponse { output:OutputLines, exit_code:ExitCode }))
80}