summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@jemstep.com>2020-03-24 17:10:59 +0200
committerJustin Worthe <justin@jemstep.com>2020-03-24 17:10:59 +0200
commita1437e90a3735b6ad9d3e16edb99e28b1b8cab74 (patch)
tree191b97ae1940216991d05e8322653a2e7d11a5a3
parentb18dc5579f2937fd1ad32b08d648ea2c9593561c (diff)
Changed merge commit reproduction to use a cloned temporary repo
This is necessary because, in newer versions of libgit, writing a tree fails if you're writing into a repo that doesn't actually have the necessary files.
-rw-r--r--src/git.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/git.rs b/src/git.rs
index 252b21d..fda6f9e 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -336,16 +336,18 @@ impl Git for LiveGit {
verification_commit: &Commit,
) -> Result<bool, Box<dyn Error>> {
use git2::MergeOptions;
- let commit = self.repo.find_commit(verification_commit.id)?;
+ let temp_repo = TempRepo::new(&self.repo, verification_commit.id)?;
+ let commit = temp_repo.repo.find_commit(verification_commit.id)?;
+ let parents = commit.parents().collect::<Vec<_>>();
- let temp_repo = TempRepo::new(commit.id())?;
- match &commit.parents().collect::<Vec<_>>()[..] {
+ match &parents[..] {
[a, b] => {
let expected_tree_id = commit.tree_id();
- let reproduced_tree_id = self
+ let reproduced_tree_id = temp_repo
.repo
.merge_commits(&a, &b, Some(MergeOptions::new().fail_on_conflict(true)))
.and_then(|mut index| index.write_tree_to(&temp_repo.repo));
+ trace!("Checking for a trivial merge commit, expecting tree_id of {}, result of reproducing tree is {:?}", expected_tree_id, reproduced_tree_id);
let matches = reproduced_tree_id
.as_ref()
.map(|id| *id == expected_tree_id)
@@ -468,7 +470,7 @@ struct TempRepo {
}
impl TempRepo {
- fn new(commit_id: Oid) -> Result<TempRepo, Box<dyn Error>> {
+ fn new(src_repo: &Repository, commit_id: Oid) -> Result<TempRepo, Box<dyn Error>> {
let max_attempts = 20;
let tmp_dir = std::env::temp_dir();
@@ -482,8 +484,11 @@ impl TempRepo {
"Created temp repo for verification: {}",
tmp_repo_path.display()
);
+ 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: Repository::init_bare(&tmp_repo_path)?,
+ repo: Repository::clone(src_path, &tmp_repo_path)?,
});
}
};