Skip to content

Commit b0e9bdf

Browse files
committed
settings: load signing parameters early, propagate config error
Typo in signing.behavior shouldn't be ignored. The idea is the same as [user] and [operation] tables. It's easier if all parameters needed to create a commit is parsed by UserSettings constructor. Another option is to make repo.start_transaction() fail on config error.
1 parent 1449c2d commit b0e9bdf

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4747
`signing.behavior`. The new option accepts `drop` (never sign), `keep` (preserve
4848
existing signatures), `own` (sign own commits), or `force` (sign all commits).
4949
Existing `signing.sign-all = true` translates to `signing.behavior = "own"`, and
50-
`false` translates to `"keep"`.
50+
`false` translates to `"keep"`. Invalid configuration is now an error.
5151

5252
### New features
5353

lib/src/config/misc.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ username = ""
2121

2222
[signing]
2323
backend = "none"
24+
behavior = "keep"
25+
# key = <none>
2426

2527
[signing.backends.gpg]
2628
allow-expired-keys = false

lib/src/settings.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct UserSettingsData {
5353
operation_timestamp: Option<Timestamp>,
5454
operation_hostname: String,
5555
operation_username: String,
56+
signing_behavior: SignBehavior,
57+
signing_key: Option<String>,
5658
}
5759

5860
#[derive(Debug, Clone)]
@@ -98,19 +100,6 @@ pub struct SignSettings {
98100
}
99101

100102
impl SignSettings {
101-
/// Load the signing settings from the config.
102-
pub fn from_settings(settings: &UserSettings) -> Self {
103-
let behavior = settings
104-
.get("signing.behavior")
105-
.unwrap_or(SignBehavior::Keep);
106-
107-
Self {
108-
behavior,
109-
user_email: settings.user_email().to_owned(),
110-
key: settings.get_string("signing.key").ok(),
111-
}
112-
}
113-
114103
/// Check if a commit should be signed according to the configured behavior
115104
/// and email.
116105
pub fn should_sign(&self, commit: &Commit) -> bool {
@@ -157,13 +146,17 @@ impl UserSettings {
157146
.optional()?;
158147
let operation_hostname = config.get("operation.hostname")?;
159148
let operation_username = config.get("operation.username")?;
149+
let signing_behavior = config.get("signing.behavior")?;
150+
let signing_key = config.get("signing.key").optional()?;
160151
let data = UserSettingsData {
161152
user_name,
162153
user_email,
163154
commit_timestamp,
164155
operation_timestamp,
165156
operation_hostname,
166157
operation_username,
158+
signing_behavior,
159+
signing_key,
167160
};
168161
Ok(UserSettings {
169162
config: Arc::new(config),
@@ -247,8 +240,11 @@ impl UserSettings {
247240
}
248241

249242
pub fn sign_settings(&self) -> SignSettings {
250-
// TODO: propagate config error
251-
SignSettings::from_settings(self)
243+
SignSettings {
244+
behavior: self.data.signing_behavior,
245+
user_email: self.data.user_email.clone(),
246+
key: self.data.signing_key.clone(),
247+
}
252248
}
253249
}
254250

0 commit comments

Comments
 (0)