diff --git a/src/config.rs b/src/config.rs index f31b5e8..4605cb9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,20 +17,14 @@ pub struct ConfigFile { impl fmt::Display for ConfigFile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let branches_list = match &self.config.branches { - None => String::from("All branches"), - Some(vec) => { - let mut out = String::from("["); - for i in 0..vec.len() { - out = format!("{}{}", out, vec[i]); - if i < vec.len() - 1 { - out.push_str(", "); - } - } - out.push(']'); - out + let mut branches_list = String::from("["); + for i in 0..self.config.branches.len() { + branches_list = format!("{}{}", branches_list, &self.config.branches[i]); + if i < self.config.branches.len() - 1 { + branches_list.push_str(", "); } - }; + } + branches_list.push(']'); let mut to_list = String::from("["); for i in 0..self.config.to.len() { @@ -88,7 +82,7 @@ impl fmt::Display for ConfigFile { pub struct Config { pub from: String, pub to: Vec, - pub branches: Option>, + pub branches: Vec, pub work_dir: Option, pub git: Git, pub schedule: Schedule diff --git a/src/refractr.rs b/src/refractr.rs index cdf4eae..152011c 100644 --- a/src/refractr.rs +++ b/src/refractr.rs @@ -35,53 +35,25 @@ impl Refractr { work_dir.to_string_lossy().to_string() } - fn get_branches(&self, repo: &Repository, branches: &Option>, refs: bool) -> Vec { - match branches { - Some(repo_branches) => { - if refs { - let mut refs_branches = Vec::new(); - for branch in repo_branches { - refs_branches.push(format!("refs/heads/{}", branch)); - } - refs_branches - } else { - repo_branches.to_vec() - } - }, - None => { - let mut strings = Vec::new(); - let remote_branches = match repo.branches(Some(git2::BranchType::Remote)) { - Ok(b) => b, - Err(e) => panic!("refractr: failed to get branches: {}", e) - }; - for branch in remote_branches { - if let Ok((b, _)) = branch { - if let Ok(Some(name)) = b.name() { - if refs { - strings.push(format!("refs/heads/{}", name.to_string())) - } else { - strings.push(name.to_string()); - } - } - } - } - strings - } + fn get_refs(&self, branches: &Vec) -> Vec { + let mut refs_branches = Vec::new(); + for branch in branches { + refs_branches.push(format!("refs/heads/{}", branch)); } + refs_branches } - fn fast_forward(&self, repo_dir: &str, branches: &Option>) -> Result<(), Error> { + fn fast_forward(&self, repo_dir: &str, branches: &Vec) -> Result<(), Error> { let repo = Repository::open(repo_dir)?; - let branch_list: Vec = self.get_branches(&repo, branches, false); common::verbose(self.verbose, 2, format!("Pulling origin")); - repo.find_remote("origin")?.fetch(&branch_list, None, None)?; + repo.find_remote("origin")?.fetch(&branches, None, None)?; let fetch_head = repo.find_reference("FETCH_HEAD")?; let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)?; let analysis = repo.merge_analysis(&[&fetch_commit])?; if analysis.0.is_fast_forward() { - for branch in branch_list { + for branch in branches { let refname = format!("refs/heads/{}", branch); let mut reference = repo.find_reference(&refname)?; reference.set_target(fetch_commit.id(), "Fast-forward")?; @@ -129,14 +101,15 @@ impl Refractr { for i in cert.as_hostkey().unwrap().hash_sha256().unwrap().to_vec() { sha256.push_str(&hex::encode(i.to_string())); } - eprintln!("warning: trusting unknown host {} with sha256 host key {}", url, hex::encode(cert.as_hostkey().unwrap().hash_sha256().unwrap().to_vec())); + eprintln!("refractr: warning: implicitly trusting unknown host {} with sha256 host key {}", url, hex::encode(cert.as_hostkey().unwrap().hash_sha256().unwrap().to_vec())); + eprintln!("refractr: warning: to ignore this error in the future, add this host to your known_hosts file"); Ok(CertificateCheckStatus::CertificateOk) }); let mut push_options = PushOptions::new(); push_options.remote_callbacks(callbacks); let mut refs = Vec::new(); - let strings = self.get_branches(&repo, &cfg.branches, true); + let strings = self.get_refs(&cfg.branches); for branch in &strings { refs.push(branch.as_str()); }