Skip to content

Commit

Permalink
test: add failing test for nickgerace#202
Browse files Browse the repository at this point in the history
  • Loading branch information
AckslD committed Nov 9, 2022
1 parent b0f3361 commit c636d32
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions crates/gfold/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ mod tests {
use anyhow::{anyhow, Result};
use git2::ErrorCode;
use git2::Repository;
use git2::Signature;
use git2::Oid;
use pretty_assertions::assert_eq;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -98,6 +100,8 @@ mod tests {
return Err(e.into());
}
}

create_branch(&repository, "feat")?;
}
}

Expand Down Expand Up @@ -225,4 +229,42 @@ mod tests {
}
Ok(())
}

fn create_branch(repository: &Repository, name: &str) -> Result<()> {
// we need to commit something before branching
let commit_oid = commit(repository)?;
repository.branch(name, &repository.find_commit(commit_oid).unwrap(), true).unwrap();

Ok(())
}

// taken from https://github.com/rust-lang/git2-rs/pull/885
fn commit(repository: &Repository) -> Result<Oid> {
// We will commit the content of the index
let mut index = repository.index()?;
let tree_oid = index.write_tree()?;
let tree = repository.find_tree(tree_oid)?;

let parent_commit = match repository.revparse_single("HEAD") {
Ok(obj) => Some(obj.into_commit().unwrap()),
// First commit so no parent commit
Err(e) if e.code() == ErrorCode::NotFound => None,
Err(_e) => panic!(),
};

let mut parents = Vec::new();
if parent_commit.is_some() {
parents.push(parent_commit.as_ref().unwrap());
}

let sig = Signature::now("Bob", "bob@bob").unwrap();
Ok(repository.commit(
Some("HEAD"),
&sig,
&sig,
"hello",
&tree,
&parents[..],
)?)
}
}

0 comments on commit c636d32

Please sign in to comment.