From 15ed191fb7f5469ee61a416ccd5e34d74a32f01a Mon Sep 17 00:00:00 2001 From: Michal Date: Fri, 22 Jul 2022 16:57:48 +0100 Subject: [PATCH] Added new comments --- src/operations/pull.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/operations/pull.rs b/src/operations/pull.rs index 671b125..849a80d 100644 --- a/src/operations/pull.rs +++ b/src/operations/pull.rs @@ -2,7 +2,7 @@ use std::env; use std::process::Command; use crate::info; -use crate::{crash, internal::AppExitCode, workspace::read_cfg, log}; +use crate::{crash, internal::AppExitCode, log, workspace::read_cfg}; fn do_the_pulling(repos: Vec, verbose: bool, smart_pull: bool) { for repo in repos { @@ -10,23 +10,32 @@ fn do_the_pulling(repos: Vec, verbose: bool, smart_pull: bool) { let root_dir = env::current_dir().unwrap(); log!(verbose, "Root dir: {:?}", root_dir); + // Enter repo dir info!("Entering working directory: {}", &repo); env::set_current_dir(repo).unwrap(); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); + // Pull log!(verbose, "Pulling"); if smart_pull { + // Just update the remote + log!(verbose, "Smart pull"); Command::new("git") .args(&["remote", "update"]) .spawn() .unwrap() .wait() .unwrap(); - let output = Command::new("git") - .arg("status") - .output() - .unwrap(); - if String::from_utf8(output.stdout).unwrap().to_string().contains("Your branch is behind") { + + // Check the repository status + let output = Command::new("git").arg("status").output().unwrap(); + + // If there are changes, pull normally + if String::from_utf8(output.stdout) + .unwrap() + .to_string() + .contains("Your branch is behind") + { Command::new("git") .arg("pull") .spawn() @@ -34,9 +43,12 @@ fn do_the_pulling(repos: Vec, verbose: bool, smart_pull: bool) { .wait() .unwrap(); } else { + // If there are no changes, alert the user info!("No changes to pull"); } } else { + // Pull normally + log!(verbose, "Normal pull"); Command::new("git") .arg("pull") .spawn() @@ -55,6 +67,7 @@ fn do_the_pulling(repos: Vec, verbose: bool, smart_pull: bool) { } pub fn pull(packages: Vec, exclude: Vec, verbose: bool) { + // Read config file let config = read_cfg(verbose); log!(verbose, "Config: {:?}", config); // If no packages are specified, imply all @@ -65,7 +78,8 @@ pub fn pull(packages: Vec, exclude: Vec, verbose: bool) { log!(verbose, "Smart pull: {}", smart_pull); // Read repos from config - let repos = config.repo + let repos = config + .repo .iter() .map(|x| x.name.clone()) .collect::>();