test: set name and email for repository fixture
In fresh environments, without a global git config, the `user.name` and `user.email` will not be set for the fixture repository. This causes issues when tests are run and attempt to call `git2::Signature::now` – it will fail to read a user name and email for the commit. To remedy this, the name and email are set for the repository when initialising it.
This commit is contained in:
parent
59a1021410
commit
f5fa84fac6
|
|
@ -81,12 +81,15 @@ pub fn project<P: AsRef<Path>, G: Signer>(
|
||||||
/// Creates a regular repository at the given path with a couple of commits.
|
/// Creates a regular repository at the given path with a couple of commits.
|
||||||
pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
||||||
let repo = git2::Repository::init(path).unwrap();
|
let repo = git2::Repository::init(path).unwrap();
|
||||||
let sig = git2::Signature::new(
|
let user_name = "anonymous";
|
||||||
"anonymous",
|
let user_email = "anonymous@radicle.xyz";
|
||||||
"anonymous@radicle.xyz",
|
{
|
||||||
&git2::Time::new(RADICLE_EPOCH, 0),
|
let mut config = repo.config().unwrap();
|
||||||
)
|
config.set_str("user.name", user_name).unwrap();
|
||||||
.unwrap();
|
config.set_str("user.email", user_email).unwrap();
|
||||||
|
}
|
||||||
|
let sig =
|
||||||
|
git2::Signature::new(user_name, user_email, &git2::Time::new(RADICLE_EPOCH, 0)).unwrap();
|
||||||
let head = git::initial_commit(&repo, &sig).unwrap();
|
let head = git::initial_commit(&repo, &sig).unwrap();
|
||||||
let tree = git::write_tree(Path::new("README"), "Hello World!\n".as_bytes(), &repo).unwrap();
|
let tree = git::write_tree(Path::new("README"), "Hello World!\n".as_bytes(), &repo).unwrap();
|
||||||
let oid = {
|
let oid = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue