radicle/test/fixtures: Use "radicle.xyz" as `const`
Ideally, we would like to use a name that is compliant with RFC 2606, such as "radicle.example.com", but this would change *lots* of hashes, which is not worth the hassle. Instead, make changing this in the future as easy as changing one constant.
This commit is contained in:
parent
1a3fda547a
commit
79505fa905
|
|
@ -15,6 +15,12 @@ use crate::storage::refs::SignedRefs;
|
||||||
/// The birth of the radicle project, January 1st, 2018.
|
/// The birth of the radicle project, January 1st, 2018.
|
||||||
pub const RADICLE_EPOCH: i64 = 1514817556;
|
pub const RADICLE_EPOCH: i64 = 1514817556;
|
||||||
|
|
||||||
|
const USER_NAME: &str = "anonymous";
|
||||||
|
|
||||||
|
// TODO: Next time we do something that changes all hashes,
|
||||||
|
// also change this to "anonymous@radicle.example.com".
|
||||||
|
const USER_EMAIL: &str = "anonymous@radicle.xyz";
|
||||||
|
|
||||||
/// Create a new user info object.
|
/// Create a new user info object.
|
||||||
pub fn user() -> git::UserInfo {
|
pub fn user() -> git::UserInfo {
|
||||||
git::UserInfo {
|
git::UserInfo {
|
||||||
|
|
@ -94,15 +100,14 @@ pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
||||||
git2::RepositoryInitOptions::new().external_template(false),
|
git2::RepositoryInitOptions::new().external_template(false),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user_name = "anonymous";
|
|
||||||
let user_email = "anonymous@radicle.xyz";
|
|
||||||
{
|
{
|
||||||
let mut config = repo.config().unwrap();
|
let mut config = repo.config().unwrap();
|
||||||
config.set_str("user.name", user_name).unwrap();
|
config.set_str("user.name", USER_NAME).unwrap();
|
||||||
config.set_str("user.email", user_email).unwrap();
|
config.set_str("user.email", USER_EMAIL).unwrap();
|
||||||
}
|
}
|
||||||
let sig =
|
let sig =
|
||||||
git2::Signature::new(user_name, user_email, &git2::Time::new(RADICLE_EPOCH, 0)).unwrap();
|
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 = {
|
||||||
|
|
@ -130,12 +135,8 @@ pub fn repository<P: AsRef<Path>>(path: P) -> (git2::Repository, git2::Oid) {
|
||||||
/// Create an empty commit on the current branch.
|
/// Create an empty commit on the current branch.
|
||||||
pub fn commit(msg: &str, parents: &[git2::Oid], repo: &git2::Repository) -> git::Oid {
|
pub fn commit(msg: &str, parents: &[git2::Oid], repo: &git2::Repository) -> git::Oid {
|
||||||
let head = repo.head().unwrap();
|
let head = repo.head().unwrap();
|
||||||
let sig = git2::Signature::new(
|
let sig =
|
||||||
"anonymous",
|
git2::Signature::new(USER_NAME, USER_EMAIL, &git2::Time::new(RADICLE_EPOCH, 0)).unwrap();
|
||||||
"anonymous@radicle.xyz",
|
|
||||||
&git2::Time::new(RADICLE_EPOCH, 0),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let tree = head.peel_to_commit().unwrap().tree().unwrap();
|
let tree = head.peel_to_commit().unwrap().tree().unwrap();
|
||||||
let parents = parents
|
let parents = parents
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -153,12 +154,8 @@ pub fn tag(name: &str, message: &str, commit: git2::Oid, repo: &git2::Repository
|
||||||
let target = repo
|
let target = repo
|
||||||
.find_object(commit, Some(git2::ObjectType::Commit))
|
.find_object(commit, Some(git2::ObjectType::Commit))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tagger = git2::Signature::new(
|
let tagger =
|
||||||
"anonymous",
|
git2::Signature::new(USER_NAME, USER_EMAIL, &git2::Time::new(RADICLE_EPOCH, 0)).unwrap();
|
||||||
"anonymous@radicle.xyz",
|
|
||||||
&git2::Time::new(RADICLE_EPOCH, 0),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
repo.tag(name, &target, &tagger, message, false)
|
repo.tag(name, &target, &tagger, message, false)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into()
|
.into()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue