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