From 88fc4f178259397b2f1cc4a055dd0ed3596ae1ff Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 13 Feb 2023 15:54:47 +0000 Subject: [PATCH] radicle: ensure stable commits for Docs `Doc::commit` used `git2::Signature::now` when committing the document to the repository. This results in the commits always changing and not allowing us to test outputs of our CLI commands that would wish to output the SHA. Make `Doc::commit` reproducible in debug mode using `debug_assertions` and checking the `RAD_COMMIT_TIME` environment variable. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle/src/identity/doc.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/radicle/src/identity/doc.rs b/radicle/src/identity/doc.rs index c2e1a61e..fed53a4a 100644 --- a/radicle/src/identity/doc.rs +++ b/radicle/src/identity/doc.rs @@ -276,6 +276,17 @@ impl Doc { .signature() .or_else(|_| git2::Signature::now("radicle", remote.to_string().as_str()))?; + #[cfg(debug_assertions)] + let sig = 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 { + sig + }; + let mut msg = format!("{}\n\n", msg.trim()); for (key, sig) in signatures { writeln!(&mut msg, "{}: {key} {sig}", trailers::SIGNATURE_TRAILER)