diff --git a/config.example.toml b/config.example.toml index 3d549d67..9f12c742 100644 --- a/config.example.toml +++ b/config.example.toml @@ -13,6 +13,9 @@ # Arguments to pass SSH when upgrading remote systems #ssh_arguments = "-o ConnectTimeout=2" +# Arguments to pass Git when pulling Repositories +#git_arguments = "--rebase --autostash" + # Commands to run before anything #[pre_commands] #"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak" diff --git a/src/config.rs b/src/config.rs index e09227b8..c1e79764 100644 --- a/src/config.rs +++ b/src/config.rs @@ -91,6 +91,7 @@ pub struct ConfigFile { disable: Option>, remote_topgrades: Option>, ssh_arguments: Option, + git_arguments: Option, } impl ConfigFile { @@ -279,6 +280,11 @@ impl Config { &self.config_file.ssh_arguments } + /// Extra Git arguments + pub fn git_arguments(&self) -> &Option { + &self.config_file.git_arguments + } + /// Prompt for a key before exiting pub fn keep_at_end(&self) -> bool { self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok() diff --git a/src/main.rs b/src/main.rs index 635db2ff..cd4b7073 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,7 +245,7 @@ fn run() -> Result<(), Error> { execute( &mut report, "Git repositories", - || git.multi_pull(&git_repos, run_type), + || git.multi_pull(&git_repos, run_type, config.git_arguments()), config.no_retry(), )?; } diff --git a/src/steps/git.rs b/src/steps/git.rs index 756b72aa..9698684c 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -74,7 +74,12 @@ impl Git { None } - pub fn multi_pull(&self, repositories: &Repositories, run_type: RunType) -> Result<(), Error> { + pub fn multi_pull( + &self, + repositories: &Repositories, + run_type: RunType, + extra_arguments: &Option, + ) -> Result<(), Error> { if repositories.repositories.is_empty() { return Ok(()); } @@ -103,51 +108,55 @@ impl Git { println!("{} {}", style("Pulling").cyan().bold(), path); - Command::new(git) - .args(&["pull", "--ff-only"]) - .current_dir(&repo) - .output_async() - .then(move |result| match result { - Ok(output) => { - if output.status.success() { - let after_revision = get_head_revision(&cloned_git, &repo); + let mut command = Command::new(git); - if before_revision != after_revision - && after_revision.is_some() - && before_revision.is_some() - { - println!("{} {}:", style("Changed").yellow().bold(), path); - Command::new(&cloned_git) - .current_dir(&repo) - .args(&[ - "log", - "--no-decorate", - "--oneline", - &format!("{}..{}", before_revision.unwrap(), after_revision.unwrap()), - ]) - .spawn() - .unwrap() - .wait() - .unwrap(); - println!(); - } else { - println!("{} {}", style("Up-to-date").green().bold(), path); - } + command.args(&["pull", "--ff-only"]).current_dir(&repo); - Ok(true) as Result + if let Some(extra_arguments) = extra_arguments { + command.args(extra_arguments.split_whitespace()); + } + + command.output_async().then(move |result| match result { + Ok(output) => { + if output.status.success() { + let after_revision = get_head_revision(&cloned_git, &repo); + + if before_revision != after_revision + && after_revision.is_some() + && before_revision.is_some() + { + println!("{} {}:", style("Changed").yellow().bold(), path); + Command::new(&cloned_git) + .current_dir(&repo) + .args(&[ + "log", + "--no-decorate", + "--oneline", + &format!("{}..{}", before_revision.unwrap(), after_revision.unwrap()), + ]) + .spawn() + .unwrap() + .wait() + .unwrap(); + println!(); } else { - println!("{} pulling {}", style("Failed").red().bold(), path); - if let Ok(text) = std::str::from_utf8(&output.stderr) { - print!("{}", text); - } - Ok(false) + println!("{} {}", style("Up-to-date").green().bold(), path); + } + + Ok(true) as Result + } else { + println!("{} pulling {}", style("Failed").red().bold(), path); + if let Ok(text) = std::str::from_utf8(&output.stderr) { + print!("{}", text); } - } - Err(e) => { - println!("{} pulling {}: {}", style("Failed").red().bold(), path, e); Ok(false) } - }) + } + Err(e) => { + println!("{} pulling {}: {}", style("Failed").red().bold(), path, e); + Ok(false) + } + }) }) .collect();