Added new smart_pull option

main
Michal 2 years ago
parent e7e6b38f5e
commit 61d2368aca

@ -1,6 +1,7 @@
mode = "repository" mode = "repository"
name = "test" name = "test"
sign = false sign = false
smart_pull = true
repo = [ repo = [
"1::amethyst", "1::amethyst",

@ -3,8 +3,9 @@ use serde_derive::Deserialize;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
pub mode: String, pub mode: String,
pub sign: bool,
pub name: Option<String>, pub name: Option<String>,
pub sign: bool,
pub smart_pull: bool,
pub repo: Vec<Repo>, pub repo: Vec<Repo>,
} }
@ -18,8 +19,9 @@ pub struct Repo {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct UnexpandedConfig { pub struct UnexpandedConfig {
pub mode: String, pub mode: String,
pub sign: bool,
pub name: Option<String>, pub name: Option<String>,
pub sign: bool,
pub smart_pull: bool,
pub repo: Vec<String>, pub repo: Vec<String>,
pub urls: Vec<String>, pub urls: Vec<String>,
} }

@ -2,24 +2,48 @@ use std::env;
use std::process::Command; use std::process::Command;
use crate::info; use crate::info;
use crate::{crash, internal::AppExitCode, log}; use crate::{crash, internal::AppExitCode, workspace::read_cfg, log};
fn do_the_pulling(repos: Vec<String>, verbose: bool) { fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool) {
for repo in repos { for repo in repos {
// Set root dir to return after each git pull // Set root dir to return after each git pull
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);
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());
log!(verbose, "Pulling");
Command::new("git")
.arg("pull")
.spawn()
.unwrap()
.wait()
.unwrap();
log!(verbose, "Pulling");
if 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") {
Command::new("git")
.arg("pull")
.spawn()
.unwrap()
.wait()
.unwrap();
} else {
info!("No changes to pull");
}
} else {
Command::new("git")
.arg("pull")
.spawn()
.unwrap()
.wait()
.unwrap();
}
// Return to root dir // Return to root dir
env::set_current_dir(root_dir).unwrap(); env::set_current_dir(root_dir).unwrap();
log!( log!(
@ -31,13 +55,17 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool) {
} }
pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) { pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) {
let config = read_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// If no packages are specified, imply all // If no packages are specified, imply all
let all = packages.is_empty(); let all = packages.is_empty();
log!(verbose, "All: {}", all); log!(verbose, "All: {}", all);
// Read smart_pull from config
let smart_pull = config.smart_pull;
log!(verbose, "Smart pull: {}", smart_pull);
// Read repos from config file // Read repos from config
let repos = crate::workspace::read_cfg(verbose) let repos = config.repo
.repo
.iter() .iter()
.map(|x| x.name.clone()) .map(|x| x.name.clone())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
@ -63,5 +91,5 @@ pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) {
// Pull! // Pull!
log!(verbose, "Pulling {:?}", repos_applicable); log!(verbose, "Pulling {:?}", repos_applicable);
do_the_pulling(repos_applicable, verbose); do_the_pulling(repos_applicable, verbose, smart_pull);
} }

@ -61,6 +61,7 @@ pub fn read_cfg(verbose: bool) -> Config {
mode: config.mode, mode: config.mode,
sign: config.sign, sign: config.sign,
name: config.name, name: config.name,
smart_pull: config.smart_pull,
repo: expanded_repos, repo: expanded_repos,
}; };
log!(verbose, "Config: {:?}", conf); log!(verbose, "Config: {:?}", conf);

Loading…
Cancel
Save