From d8711a8d43dc919fe39ae4b7c2f7b24667f5d470 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 16 May 2023 11:47:51 +0200 Subject: [PATCH] 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 --- radicle/src/storage/refs.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/radicle/src/storage/refs.rs b/radicle/src/storage/refs.rs index 5a4b82c7..af0fc1e4 100644 --- a/radicle/src/storage/refs.rs +++ b/radicle/src/storage/refs.rs @@ -315,6 +315,18 @@ impl SignedRefs { 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::().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,