Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Git/
HandlePull.rs

1//! `localGit:pull(operationId, repoPath) -> bool`. Three-call
2//! sequence: read HEAD, `pull --ff-only`, read HEAD again.
3//! Returns `true` when the second HEAD differs from the first
4//! (i.e. the pull actually moved the branch). `--ff-only`
5//! avoids surprise merge commits - callers handle non-FF cases
6//! explicitly.
7
8use serde_json::{Value, json};
9
10use crate::IPC::WindServiceHandlers::{Git::Shared::RunGit::Fn as RunGit, Utilities::JsonValueHelpers::arg_string};
11
12pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
13	let OperationId = arg_string(&Arguments, 0);
14
15	let RepoPath = arg_string(&Arguments, 1);
16
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
24	if BeforeExit != 0 {
25		return Err("git:pull: failed to read HEAD before pull".to_string());
26	}
27
28	let (PullExit, _, PullStderr) =
29		RunGit(&OperationId, &["pull".to_string(), "--ff-only".to_string()], Some(&RepoPath)).await?;
30
31	if PullExit != 0 {
32		return Err(format!("git pull failed: {}", PullStderr));
33	}
34
35	let (AfterExit, After, _) =
36		RunGit(&OperationId, &["rev-parse".to_string(), "HEAD".to_string()], Some(&RepoPath)).await?;
37
38	if AfterExit != 0 {
39		return Err("git:pull: failed to read HEAD after pull".to_string());
40	}
41
42	Ok(json!(Before.trim() != After.trim()))
43}