ok/jj
1
0
Fork 0
forked from mirrors/jj

settings: allow setting author/commit timestamp via config

I'm not sure it'll be useful, but it seems nice to be able to set the
same values via config or environment variables. Perhap we should
simply use `config::Environment` to make everything configurable via
environment variables, but I'll leave that for later.
This commit is contained in:
Martin von Zweigbergk 2022-03-09 12:51:35 -08:00 committed by Martin von Zweigbergk
parent e0115d2af7
commit 18861c67c3

View file

@ -70,6 +70,12 @@ impl UserSettings {
)?;
}
let mut env_config = config::Config::new();
if let Ok(timestamp_str) = env::var("JJ_TIMESTAMP") {
env_config.set("user.timestamp", timestamp_str)?;
}
config.merge(env_config)?;
Ok(UserSettings { config })
}
@ -97,7 +103,7 @@ impl UserSettings {
}
pub fn signature(&self) -> Signature {
let timestamp = match env::var("JJ_TIMESTAMP") {
let timestamp = match self.config.get_str("user.timestamp") {
Ok(timestamp_str) => match DateTime::parse_from_rfc3339(&timestamp_str) {
Ok(datetime) => Timestamp::from_datetime(datetime),
Err(_) => Timestamp::now(),