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:
parent
e0115d2af7
commit
18861c67c3
1 changed files with 7 additions and 1 deletions
|
@ -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(×tamp_str) {
|
||||
Ok(datetime) => Timestamp::from_datetime(datetime),
|
||||
Err(_) => Timestamp::now(),
|
||||
|
|
Loading…
Reference in a new issue