-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
templates: add cryptographic_signature display to default formats
Cryptographic signature support in templates was added in c99c97c (#4853), but has to be manually configured. This adds some defaults to the built-in config. Instead of having separate `builtin_*_with_sig` aliases, this adds to the aliases that actually format commits. Since signature verification is slow, this is disabled by default. To enable it, override the `should_show_cryptographic_signature()` template alias like so: [ui] show-cryptographic-signatures = true [template-aliases] 'format_short_cryptographic_signature(signature)' = ... 'format_detailed_cryptographic_signature(signature)' = ... Note that the two formatting functions take `Option<CryptographicSignature>`, not `CryptographicSignature`. This allows you to display a custom message if a signature is not found, but will emit an error if you do not check for signature presence. [template-aliases] 'format_detailed_cryptographic_signature(signature)' = ''' if(signature, "message if present", "message if missing", ) '''
- Loading branch information
1 parent
9872427
commit 8ee936f
Showing
7 changed files
with
147 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1214,22 +1214,81 @@ fn test_log_diff_predefined_formats() { | |
fn test_signature_templates() { | ||
let test_env = TestEnvironment::default(); | ||
|
||
test_env.add_config(r#"signing.sign-all = true"#); | ||
test_env.add_config(r#"signing.backend = "test""#); | ||
|
||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
let template = r#"if(signature, | ||
signature.status() ++ " " ++ signature.display(), | ||
"no" | ||
) ++ " signature""#; | ||
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "unsigned"]); | ||
test_env.add_config("signing.sign-all = true"); | ||
test_env.add_config("signing.backend = 'test'"); | ||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "signed"]); | ||
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); | ||
insta::assert_snapshot!(stdout, @r" | ||
@ good test-display signature | ||
◆ no signature"); | ||
let template = r#" | ||
if(signature, | ||
signature.status() ++ " " ++ signature.display(), | ||
"no", | ||
) ++ " signature""#; | ||
|
||
// show that signatures can render | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); | ||
insta::assert_snapshot!(stdout, @r#" | ||
@ good test-display signature | ||
○ no signature | ||
◆ no signature | ||
"#); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["show", "-T", template]); | ||
insta::assert_snapshot!(stdout, @"good test-display signature"); | ||
insta::assert_snapshot!(stdout, @r#"good test-display signature"#); | ||
|
||
// builtin templates | ||
test_env.add_config("ui.show-cryptographic-signatures = true"); | ||
|
||
let args: &[_] = &["log", "-r", "..", "-T"]; | ||
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &[args, &["builtin_log_oneline"]].concat()); | ||
insta::assert_snapshot!(stdout, @r#" | ||
@ rlvkpnrz test.user 2001-02-03 08:05:09 a0909ee9 [✓︎] (empty) signed | ||
○ qpvuntsm test.user 2001-02-03 08:05:08 879d5d20 (empty) unsigned | ||
│ | ||
~ | ||
"#); | ||
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &[args, &["builtin_log_compact"]].concat()); | ||
insta::assert_snapshot!(stdout, @r#" | ||
@ rlvkpnrz [email protected] 2001-02-03 08:05:09 a0909ee9 [✓︎] | ||
│ (empty) signed | ||
○ qpvuntsm [email protected] 2001-02-03 08:05:08 879d5d20 | ||
│ (empty) unsigned | ||
~ | ||
"#); | ||
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &[args, &["builtin_log_detailed"]].concat()); | ||
insta::assert_snapshot!(stdout, @r#" | ||
@ Commit ID: a0909ee96bb5c66311a0c579dc8ebed4456dfc1b | ||
│ Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp | ||
│ Author : Test User <[email protected]> (2001-02-03 08:05:09) | ||
│ Committer: Test User <[email protected]> (2001-02-03 08:05:09) | ||
│ Signature: good signature by test-display | ||
│ | ||
│ signed | ||
│ | ||
○ Commit ID: 879d5d20fea5930f053e0817033ad4aba924a361 | ||
│ Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu | ||
~ Author : Test User <[email protected]> (2001-02-03 08:05:08) | ||
Committer: Test User <[email protected]> (2001-02-03 08:05:08) | ||
Signature: (no signature) | ||
unsigned | ||
"#); | ||
|
||
// customization point | ||
let config_val = r#"template-aliases."format_short_cryptographic_signature(signature)"="'status: ' ++ signature.status()""#; | ||
let stdout = test_env.jj_cmd_success( | ||
&repo_path, | ||
&[args, &["builtin_log_oneline", "--config", config_val]].concat(), | ||
); | ||
insta::assert_snapshot!(stdout, @r#" | ||
@ rlvkpnrz test.user 2001-02-03 08:05:09 a0909ee9 status: good (empty) signed | ||
○ qpvuntsm test.user 2001-02-03 08:05:08 879d5d20 status: <Error: No CryptographicSignature available> (empty) unsigned | ||
│ | ||
~ | ||
"#); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters