Skip to content

Commit 6d14f1a

Browse files
feat: support x509 commit signing
1 parent b1db21e commit 6d14f1a

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
![blame-goto-line](assets/blame-goto-line.png)
3535

3636
### Added
37+
* support x509 commit signing [[@kaden-l-nelson](https://github.com/kaden-l-nelson)] ([#2514](https://github.com/gitui-org/gitui/issues/2514))
3738
* support choosing checkout branch method when status is not empty [[@fatpandac](https://github.com/fatpandac)] ([#2404](https://github.com/extrawurst/gitui/issues/2404))
3839
* support pre-push hook [[@xlai89](https://github.com/xlai89)] ([#1933](https://github.com/extrawurst/gitui/issues/1933))
3940
* message tab supports pageUp and pageDown [[@xlai89](https://github.com/xlai89)] ([#2623](https://github.com/extrawurst/gitui/issues/2623))

asyncgit/src/sync/sign.rs

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,24 @@ impl SignBuilder {
113113
// Variants are described in the git config documentation
114114
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
115115
match format.as_str() {
116-
"openpgp" => {
116+
"openpgp" | "x509" => {
117117
// Try to retrieve the gpg program from the git configuration,
118118
// moving from the least to the most specific config key,
119119
// defaulting to "gpg" if nothing is explicitly defined (per git's implementation)
120120
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
121-
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
122121
let program = config
123-
.get_string("gpg.openpgp.program")
122+
.get_string(
123+
format!("gpg.{format}.program").as_str(),
124+
)
124125
.or_else(|_| config.get_string("gpg.program"))
125-
.unwrap_or_else(|_| "gpg".to_string());
126+
.unwrap_or_else(|_| {
127+
(if format == "x509" {
128+
"gpgsm"
129+
} else {
130+
"gpg"
131+
})
132+
.to_string()
133+
});
126134

127135
// Optional signing key.
128136
// If 'user.signingKey' is not set, we'll use 'user.name' and 'user.email'
@@ -152,9 +160,6 @@ impl SignBuilder {
152160
signing_key,
153161
}))
154162
}
155-
"x509" => Err(SignBuilderError::MethodNotImplemented(
156-
String::from("x509"),
157-
)),
158163
"ssh" => {
159164
let ssh_signer = config
160165
.get_string("user.signingKey")
@@ -439,4 +444,58 @@ mod tests {
439444

440445
Ok(())
441446
}
447+
448+
#[test]
449+
fn test_x509_program_defaults() -> Result<()> {
450+
let (_tmp_dir, repo) = repo_init_empty()?;
451+
452+
{
453+
let mut config = repo.config()?;
454+
config.set_str("gpg.format", "x509")?;
455+
}
456+
457+
let sign =
458+
SignBuilder::from_gitconfig(&repo, &repo.config()?)?;
459+
460+
// default x509 program should be gpgsm
461+
assert_eq!("gpgsm", sign.program());
462+
// default signing key should be "name <email>" when not specified
463+
assert_eq!("name <email>", sign.signing_key());
464+
465+
Ok(())
466+
}
467+
468+
#[test]
469+
fn test_x509_program_configs() -> Result<()> {
470+
let (_tmp_dir, repo) = repo_init_empty()?;
471+
472+
{
473+
let mut config = repo.config()?;
474+
config.set_str("gpg.format", "x509")?;
475+
config.set_str("gpg.program", "GPG_PROGRAM_TEST")?;
476+
}
477+
478+
let sign =
479+
SignBuilder::from_gitconfig(&repo, &repo.config()?)?;
480+
481+
// we get gpg.program, because gpg.x509.program is not set
482+
assert_eq!("GPG_PROGRAM_TEST", sign.program());
483+
484+
{
485+
let mut config = repo.config()?;
486+
config.set_str(
487+
"gpg.x509.program",
488+
"GPG_X509_PROGRAM_TEST",
489+
)?;
490+
}
491+
492+
let sign =
493+
SignBuilder::from_gitconfig(&repo, &repo.config()?)?;
494+
495+
// since gpg.x509.program is now set as well, it is more specific than
496+
// gpg.program and therefore takes precedence
497+
assert_eq!("GPG_X509_PROGRAM_TEST", sign.program());
498+
499+
Ok(())
500+
}
442501
}

0 commit comments

Comments
 (0)