From c858a18bdd1b8714c9dc97778f9899dabf606c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=B6nburg?= Date: Tue, 28 Apr 2020 20:07:20 +0200 Subject: [PATCH] Skip git repos without remotes (#398) --- src/steps/git.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/steps/git.rs b/src/steps/git.rs index b52bc0d9..8de1697d 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -49,6 +49,19 @@ fn get_head_revision(git: &Path, repo: &str) -> Option { .ok() } +fn has_remotes(git: &Path, repo: &str) -> Option { + Command::new(git) + .args(&["remote", "show"]) + .current_dir(repo) + .check_output() + .map(|output| output.lines().count() > 0) + .map_err(|e| { + error!("Error getting remotes for {}: {}", repo, e); + e + }) + .ok() +} + impl Git { pub fn new() -> Self { Self { git: which("git") } @@ -120,6 +133,17 @@ impl Git { let mut processes: Vec<_> = repositories .repositories .iter() + .filter(|repo| match has_remotes(git, repo) { + Some(false) => { + println!( + "{} {} because it has no remotes", + style("Skipping").yellow().bold(), + repo + ); + false + } + _ => true, // repo has remotes or command to check for remotes has failed. proceed to pull anyway. + }) .filter_map(|repo| { let repo = repo.clone(); let path = repo.to_string();