Added new comments

main
Michal 2 years ago
parent 61d2368aca
commit 912140b608

@ -2,7 +2,7 @@ use std::env;
use std::process::Command; use std::process::Command;
use crate::info; 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<String>, verbose: bool, smart_pull: bool) { fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool) {
for repo in repos { for repo in repos {
@ -10,23 +10,32 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool) {
let root_dir = env::current_dir().unwrap(); let root_dir = env::current_dir().unwrap();
log!(verbose, "Root dir: {:?}", root_dir); log!(verbose, "Root dir: {:?}", root_dir);
// Enter repo dir
info!("Entering working directory: {}", &repo); info!("Entering working directory: {}", &repo);
env::set_current_dir(repo).unwrap(); env::set_current_dir(repo).unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
// Pull
log!(verbose, "Pulling"); log!(verbose, "Pulling");
if smart_pull { if smart_pull {
// Just update the remote
log!(verbose, "Smart pull");
Command::new("git") Command::new("git")
.args(&["remote", "update"]) .args(&["remote", "update"])
.spawn() .spawn()
.unwrap() .unwrap()
.wait() .wait()
.unwrap(); .unwrap();
let output = Command::new("git")
.arg("status") // Check the repository status
.output() let output = Command::new("git").arg("status").output().unwrap();
.unwrap();
if String::from_utf8(output.stdout).unwrap().to_string().contains("Your branch is behind") { // If there are changes, pull normally
if String::from_utf8(output.stdout)
.unwrap()
.to_string()
.contains("Your branch is behind")
{
Command::new("git") Command::new("git")
.arg("pull") .arg("pull")
.spawn() .spawn()
@ -34,9 +43,12 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool) {
.wait() .wait()
.unwrap(); .unwrap();
} else { } else {
// If there are no changes, alert the user
info!("No changes to pull"); info!("No changes to pull");
} }
} else { } else {
// Pull normally
log!(verbose, "Normal pull");
Command::new("git") Command::new("git")
.arg("pull") .arg("pull")
.spawn() .spawn()
@ -55,6 +67,7 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool) {
} }
pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) { pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) {
// Read config file
let config = read_cfg(verbose); let config = read_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// If no packages are specified, imply all // If no packages are specified, imply all
@ -65,7 +78,8 @@ pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) {
log!(verbose, "Smart pull: {}", smart_pull); log!(verbose, "Smart pull: {}", smart_pull);
// Read repos from config // Read repos from config
let repos = config.repo let repos = config
.repo
.iter() .iter()
.map(|x| x.name.clone()) .map(|x| x.name.clone())
.collect::<Vec<String>>(); .collect::<Vec<String>>();

Loading…
Cancel
Save