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 <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
6b674a38c1
commit
88fc4f1782
|
|
@ -276,6 +276,17 @@ impl Doc<Verified> {
|
|||
.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::<i64>().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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue