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 let RepoPath = Arguments.get(1).and_then(Value::as_str).unwrap_or("").to_string();
17 if RepoPath.is_empty() {
18 return Err("git:pull requires repoPath".to_string());
19 }
20
21 let (BeforeExit, Before, _) =
22 RunGit(&OperationId, &["rev-parse".to_string(), "HEAD".to_string()], Some(&RepoPath)).await?;
23 if BeforeExit != 0 {
24 return Err("git:pull: failed to read HEAD before pull".to_string());
25 }
26
27 let (PullExit, _, PullStderr) =
28 RunGit(&OperationId, &["pull".to_string(), "--ff-only".to_string()], Some(&RepoPath)).await?;
29 if PullExit != 0 {
30 return Err(format!("git pull failed: {}", PullStderr));
31 }
32
33 let (AfterExit, After, _) =
34 RunGit(&OperationId, &["rev-parse".to_string(), "HEAD".to_string()], Some(&RepoPath)).await?;
35 if AfterExit != 0 {
36 return Err("git:pull: failed to read HEAD after pull".to_string());
37 }
38
39 Ok(json!(Before.trim() != After.trim()))
40}