Add a configuration variable to control git arguments (fix #193)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -91,6 +91,7 @@ pub struct ConfigFile {
|
||||
disable: Option<Vec<Step>>,
|
||||
remote_topgrades: Option<Vec<String>>,
|
||||
ssh_arguments: Option<String>,
|
||||
git_arguments: Option<String>,
|
||||
}
|
||||
|
||||
impl ConfigFile {
|
||||
@@ -279,6 +280,11 @@ impl Config {
|
||||
&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
|
||||
pub fn keep_at_end(&self) -> bool {
|
||||
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
||||
|
||||
@@ -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(),
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -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<String>,
|
||||
) -> 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<bool, Error>
|
||||
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<bool, Error>
|
||||
} 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user