diff --git a/radicle-cob/src/backend/git.rs b/radicle-cob/src/backend/git.rs index 4cd70cb2..131f4057 100644 --- a/radicle-cob/src/backend/git.rs +++ b/radicle-cob/src/backend/git.rs @@ -4,3 +4,8 @@ // Linking Exception. For full terms see the included LICENSE file. pub mod change; + +/// Environment variable to set to overwrite the commit date for both the author and the committer. +/// +/// The format must be a unix timestamp. +pub const RAD_COMMIT_TIME: &str = "RAD_COMMIT_TIME"; diff --git a/radicle-cob/src/backend/git/change.rs b/radicle-cob/src/backend/git/change.rs index fbe16c54..8aec7f83 100644 --- a/radicle-cob/src/backend/git/change.rs +++ b/radicle-cob/src/backend/git/change.rs @@ -11,6 +11,7 @@ use git_ext::Oid; use git_trailers::OwnedTrailer; use nonempty::NonEmpty; +use crate::git; use crate::history::entry::Timestamp; use crate::{ change::{self, store, Change}, @@ -235,13 +236,23 @@ where { let author = repo.signature()?; - let timestamp = author.when().seconds() as Timestamp; + let mut timestamp = author.when().seconds(); + let mut headers = commit::Headers::new(); headers.push( "gpgsig", &String::from_utf8(crypto::ssh::ExtendedSignature::from(signature).to_armored())?, ); - let author = commit::Author::try_from(&author)?; + let mut author = commit::Author::try_from(&author)?; + + #[cfg(debug_assertions)] + if let Ok(s) = std::env::var(git::RAD_COMMIT_TIME) { + if let Ok(v) = s.trim().parse::() { + author.time = git_commit::author::Time::new(v, 0); + timestamp = v; + } + } + let oid = Commit::new( tree.id(), parents, @@ -253,7 +264,7 @@ where ) .write(repo)?; - Ok((Oid::from(oid), timestamp)) + Ok((Oid::from(oid), timestamp as u64)) } }