Mountain/IPC/WindServiceHandlers/Git/
HandlePull.rs1#![allow(non_snake_case)]
2
3use serde_json::{Value, json};
11
12use crate::IPC::WindServiceHandlers::Git::Shared::RunGit;
13
14pub async fn HandlePull(Arguments:Vec<Value>) -> Result<Value, String> {
15 let OperationId = Arguments.first().and_then(Value::as_str).unwrap_or("").to_string();
16
17 let RepoPath = Arguments.get(1).and_then(Value::as_str).unwrap_or("").to_string();
18
19 if RepoPath.is_empty() {
20 return Err("git:pull requires repoPath".to_string());
21 }
22
23 let (BeforeExit, Before, _) =
24 RunGit(&OperationId, &["rev-parse".to_string(), "HEAD".to_string()], Some(&RepoPath)).await?;
25
26 if BeforeExit != 0 {
27 return Err("git:pull: failed to read HEAD before pull".to_string());
28 }
29
30 let (PullExit, _, PullStderr) =
31 RunGit(&OperationId, &["pull".to_string(), "--ff-only".to_string()], Some(&RepoPath)).await?;
32
33 if PullExit != 0 {
34 return Err(format!("git pull failed: {}", PullStderr));
35 }
36
37 let (AfterExit, After, _) =
38 RunGit(&OperationId, &["rev-parse".to_string(), "HEAD".to_string()], Some(&RepoPath)).await?;
39
40 if AfterExit != 0 {
41 return Err("git:pull: failed to read HEAD after pull".to_string());
42 }
43
44 Ok(json!(Before.trim() != After.trim()))
45}