From c0453584b15337affa9fab7f46257a641398bb8a Mon Sep 17 00:00:00 2001 From: alexis-opolka Date: Fri, 3 Oct 2025 20:05:31 +0200 Subject: [PATCH] feat: Added the start of the handling of the git remote update process Signed-off-by: alexis-opolka --- src/common/git.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/common/git.rs b/src/common/git.rs index c332bcd..89241b2 100644 --- a/src/common/git.rs +++ b/src/common/git.rs @@ -12,6 +12,8 @@ pub fn shallow_clone(uri: &str, target: &str, branch: &Option) -> Result Vec::from(["clone", uri, target, "--depth", "1"]) }; + debug!("{}", format!("Launching 'git {git_clone_args:?}'")); + Command::new("git") .args(git_clone_args) .spawn() @@ -112,13 +114,36 @@ pub fn diff(uri: &str) -> Result { .wait()?) } -pub fn remote_update(uri: &str) -> Result { - Ok(Command::new("git") +/// Updates the remote +pub fn remote_update(uri: &str) -> Result { + // Apparently, using the std::process::Command with git registers the output as an StdErr. + // (Is that really an error ???), we then read the stderr instead of the stdout. + + let git_remote_update_output = Command::new("git") .current_dir(&uri) - .args(["remote", "update"]) - .spawn()? - .wait()? - ) + .args(["remote", "--verbose", "update"]) + // Even if we don't use the stdout, as a matter of principle, we still pipe it + .stdout(Stdio::piped()) + // The output of the git command is stored within the stderr... + .stderr(Stdio::piped()) + .output()?; + let current_git_branch = Command::new("git") + .current_dir(&uri) + .args(["branch"]) + .stdout(Stdio::piped()) + .output()?; + let current_git_branch_str = String::from_utf8_lossy(¤t_git_branch.stdout).to_string(); + + // if in our output, we have a "[up to date] -> origin/" + // we should return true, otherwise we should return false + println!("Git Branch: {:?}", current_git_branch_str); + + // TODO: trim then RegExp match the position of the branch to extract its name and then compare the previous result + // of the remote update to check our current status. + + + + Ok(true) } /// Gets the local state of a git repository against its remote