Add a configuration variable to control git arguments (fix #193)

This commit is contained in:
Roey Darwish Dror
2019-09-04 21:31:23 +03:00
parent 8c00f1f247
commit c3a979caec
4 changed files with 59 additions and 41 deletions

View File

@@ -13,6 +13,9 @@
# Arguments to pass SSH when upgrading remote systems # Arguments to pass SSH when upgrading remote systems
#ssh_arguments = "-o ConnectTimeout=2" #ssh_arguments = "-o ConnectTimeout=2"
# Arguments to pass Git when pulling Repositories
#git_arguments = "--rebase --autostash"
# Commands to run before anything # Commands to run before anything
#[pre_commands] #[pre_commands]
#"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak" #"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak"

View File

@@ -91,6 +91,7 @@ pub struct ConfigFile {
disable: Option<Vec<Step>>, disable: Option<Vec<Step>>,
remote_topgrades: Option<Vec<String>>, remote_topgrades: Option<Vec<String>>,
ssh_arguments: Option<String>, ssh_arguments: Option<String>,
git_arguments: Option<String>,
} }
impl ConfigFile { impl ConfigFile {
@@ -279,6 +280,11 @@ impl Config {
&self.config_file.ssh_arguments &self.config_file.ssh_arguments
} }
/// Extra Git arguments
pub fn git_arguments(&self) -> &Option<String> {
&self.config_file.git_arguments
}
/// Prompt for a key before exiting /// Prompt for a key before exiting
pub fn keep_at_end(&self) -> bool { pub fn keep_at_end(&self) -> bool {
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok() self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()

View File

@@ -245,7 +245,7 @@ fn run() -> Result<(), Error> {
execute( execute(
&mut report, &mut report,
"Git repositories", "Git repositories",
|| git.multi_pull(&git_repos, run_type), || git.multi_pull(&git_repos, run_type, config.git_arguments()),
config.no_retry(), config.no_retry(),
)?; )?;
} }

View File

@@ -74,7 +74,12 @@ impl Git {
None 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<String>,
) -> Result<(), Error> {
if repositories.repositories.is_empty() { if repositories.repositories.is_empty() {
return Ok(()); return Ok(());
} }
@@ -103,11 +108,15 @@ impl Git {
println!("{} {}", style("Pulling").cyan().bold(), path); println!("{} {}", style("Pulling").cyan().bold(), path);
Command::new(git) let mut command = Command::new(git);
.args(&["pull", "--ff-only"])
.current_dir(&repo) command.args(&["pull", "--ff-only"]).current_dir(&repo);
.output_async()
.then(move |result| match result { if let Some(extra_arguments) = extra_arguments {
command.args(extra_arguments.split_whitespace());
}
command.output_async().then(move |result| match result {
Ok(output) => { Ok(output) => {
if output.status.success() { if output.status.success() {
let after_revision = get_head_revision(&cloned_git, &repo); let after_revision = get_head_revision(&cloned_git, &repo);