radicle: ensure stable sigrefs commit

When updating sigrefs with `storage::refs::save` we weren't checking
the `RAD_COMMIT_TIME` variable, so the sigrefs commit was using current
time, and we weren't able to reproduce a deterministic sigrefs commit.

Make `refs::save` reproducible in debug mode using `debug_assertions`
and checking the `RAD_COMMIT_TIME` environment variable.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez 2023-05-16 11:47:51 +02:00 committed by Alexis Sellier
parent 8202495e24
commit d8711a8d43
No known key found for this signature in database
1 changed files with 12 additions and 0 deletions

View File

@ -315,6 +315,18 @@ impl SignedRefs<Verified> {
let sigref = sigref.with_namespace(remote.into());
let author = repo.raw().signature()?;
#[cfg(debug_assertions)]
let author = if let Ok(s) = std::env::var("RAD_COMMIT_TIME") {
// SAFETY: Only used in test code.
#[allow(clippy::unwrap_used)]
let timestamp = s.trim().parse::<i64>().unwrap();
let time = git2::Time::new(timestamp, 0);
git2::Signature::new("radicle", remote.to_string().as_str(), &time)?
} else {
author
};
let commit = repo.raw().commit(
Some(&sigref),
&author,