diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/git.rs | 27 | ||||
-rw-r--r-- | src/policies.rs | 46 | ||||
-rw-r--r-- | src/policies/policy_result.rs | 10 |
5 files changed, 55 insertions, 32 deletions
@@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "capn" -version = "0.5.2" +version = "0.5.3" dependencies = [ "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "git2 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,6 +1,6 @@ [package] name = "capn" -version = "0.5.2" +version = "0.5.3" authors = ["Justin Wernick <justin@jemstep.com>"] edition = "2018" @@ -1,7 +1,7 @@ use crate::error::CapnError; use crate::keyring::Keyring; use git2; -use git2::{build::RepoBuilder, ErrorClass, ErrorCode, ObjectType, Oid, Repository}; +use git2::{ErrorClass, ErrorCode, ObjectType, Oid, Repository}; use std::cell::RefCell; use std::collections::HashMap; use std::error::Error; @@ -508,11 +508,26 @@ impl TempRepo { let src_path = src_repo.path().to_str().ok_or(Box::new(CapnError::new( "Path to the repo being verified was not valid UTF-8", )))?; - return Ok(TempRepo { - repo: RepoBuilder::new() - .bare(true) - .clone(src_path, &tmp_repo_path)?, - }); + + let result = Command::new("git") + .arg("clone") + .arg("--bare") + .arg("--shared") + .arg(src_path) + .arg(&tmp_repo_path) + .output()?; + + return if result.status.success() { + Ok(TempRepo { + repo: Repository::open(tmp_repo_path)?, + }) + } else { + debug!("Git clone Stderr: {:?}", String::from_utf8(result.stderr)); + Err(Box::new(CapnError::new(format!( + "Call to git clone while creating temp repo failed with code {:?}", + result.status.code() + )))) + }; } }; } diff --git a/src/policies.rs b/src/policies.rs index 5eed65f..cc2b71e 100644 --- a/src/policies.rs +++ b/src/policies.rs @@ -70,37 +70,35 @@ pub fn verify_git_commits<G: Git, P: Gpg>( )?; if config.verify_email_addresses { - policy_result = policy_result.and(verify_email_addresses( - &config.author_domain, - &config.committer_domain, - ¬_manually_verified_commits, - )); + policy_result = policy_result.and_then(|| { + Ok(verify_email_addresses( + &config.author_domain, + &config.committer_domain, + ¬_manually_verified_commits, + )) + })?; } - if config.verify_commit_signatures { - policy_result = policy_result.and(verify_commit_signatures::<G, P>( - git, - &gpg, - ¬_manually_verified_commits, - &mut keyring, - )?); + if config.verify_rebased { + policy_result = policy_result.and_then(|| { + verify_rebased::<G>(&all_commits, git, &ref_update, &config.override_tag_pattern) + })?; } if config.verify_different_authors { - policy_result = policy_result.and(verify_different_authors::<G>( - &all_commits, - git, - &ref_update, - )?); + policy_result = policy_result + .and_then(|| verify_different_authors::<G>(&all_commits, git, &ref_update))?; } - if config.verify_rebased { - policy_result = policy_result.and(verify_rebased::<G>( - &all_commits, - git, - &ref_update, - &config.override_tag_pattern, - )?); + if config.verify_commit_signatures { + policy_result = policy_result.and_then(|| { + verify_commit_signatures::<G, P>( + git, + &gpg, + ¬_manually_verified_commits, + &mut keyring, + ) + })?; } } diff --git a/src/policies/policy_result.rs b/src/policies/policy_result.rs index e12ff42..852c705 100644 --- a/src/policies/policy_result.rs +++ b/src/policies/policy_result.rs @@ -1,4 +1,5 @@ use git2::Oid; +use std::error::Error; use std::fmt; use std::iter; @@ -22,6 +23,15 @@ impl PolicyResult { x => x, } } + pub fn and_then( + self, + mut next: impl FnMut() -> Result<PolicyResult, Box<dyn Error>>, + ) -> Result<PolicyResult, Box<dyn Error>> { + match self { + PolicyResult::Ok => next(), + x => Ok(x), + } + } pub fn is_ok(&self) -> bool { match self { PolicyResult::Ok => true, |