Skip to content

Commit 00e9c42

Browse files
pylbrechtyuja
andcommitted
sign: add default revisions for jj sign
When signing commits with `jj sign`, one might want to use a workflow like: ```bash jj fix && jj sign .. && jj git push ``` Making the default value for `-r`/`--revisions` configurable, will allow such a workflow. Co-Authored-By: Yuya Nishihara <yuya@tcha.org>
1 parent f399c57 commit 00e9c42

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

cli/src/commands/sign.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use crate::ui::Ui;
3232
pub struct SignArgs {
3333
/// What revision(s) to sign
3434
///
35+
/// If no revisions are specified, this defaults to the `revsets.sign` setting.
36+
///
3537
/// Note that revisions are always re-signed.
3638
///
3739
/// While that leads to discomfort for users, which sign with hardware
@@ -55,10 +57,14 @@ pub fn cmd_sign(ui: &mut Ui, command: &CommandHelper, args: &SignArgs) -> Result
5557
));
5658
}
5759

58-
let to_sign: IndexSet<Commit> = workspace_command
59-
.parse_union_revsets(ui, &args.revisions)?
60-
.evaluate_to_commits()?
61-
.try_collect()?;
60+
let revset_expression = if args.revisions.is_empty() {
61+
let revset_string = workspace_command.settings().get_string("revsets.sign")?;
62+
workspace_command.parse_revset(ui, &RevisionArg::from(revset_string))?
63+
} else {
64+
workspace_command.parse_union_revsets(ui, &args.revisions)?
65+
};
66+
67+
let to_sign: IndexSet<Commit> = revset_expression.evaluate_to_commits()?.try_collect()?;
6268

6369
workspace_command.check_rewritable(to_sign.iter().ids())?;
6470

cli/src/config-schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@
512512
"type": "string",
513513
"description": "Default set of revisions to simplify when no explicit revset is given for jj simplify-parents",
514514
"default": "reachable(@, mutable())"
515+
},
516+
"sign": {
517+
"type": "string",
518+
"description": "Default set of revisions to sign when no explicit revset is given for jj sign",
519+
"default": "reachable(@, mutable())"
515520
}
516521
},
517522
"additionalProperties": {

cli/src/config/revsets.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ simplify-parents = "reachable(@, mutable())"
88
# evaluate, lengthy warning messages would be printed. Use present(expr) to
99
# suppress symbol resolution error.
1010
log = "present(@) | ancestors(immutable_heads().., 2) | present(trunk())"
11+
sign = "reachable(@, mutable())"
1112

1213
[revset-aliases]
1314
# trunk() can be overridden as '<bookmark>@<remote>'. Use present(trunk()) if

cli/tests/cli-reference@.md.snap

+2
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,8 @@ Cryptographically sign a revision
22272227

22282228
* `-r`, `--revisions <REVSETS>` — What revision(s) to sign
22292229

2230+
If no revisions are specified, this defaults to the `revsets.sign` setting.
2231+
22302232
Note that revisions are always re-signed.
22312233

22322234
While that leads to discomfort for users, which sign with hardware devices, as of now we cannot reliably check if a commit is already signed by the user without creating a signature (see https://github.com/jj-vcs/jj/issues/5786).

cli/tests/test_sign_unsign_commands.rs

+36
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ backend = "test"
9898
");
9999
}
100100

101+
#[test]
102+
fn test_sign_default_revset() {
103+
let test_env = TestEnvironment::default();
104+
105+
test_env.add_config(
106+
r#"
107+
[ui]
108+
show-cryptographic-signatures = true
109+
110+
[signing]
111+
behavior = "keep"
112+
backend = "test"
113+
"#,
114+
);
115+
116+
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
117+
let repo_path = test_env.env_root().join("repo");
118+
test_env
119+
.run_jj_in(&repo_path, ["commit", "-m", "one"])
120+
.success();
121+
122+
test_env.add_config("revsets.sign = '@'");
123+
124+
test_env.run_jj_in(&repo_path, ["sign"]).success();
125+
126+
let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()"]);
127+
insta::assert_snapshot!(output, @r"
128+
@ rlvkpnrz test.user@example.com 2001-02-03 08:05:09 8623fdf2 [✓︎]
129+
│ (empty) (no description set)
130+
○ qpvuntsm test.user@example.com 2001-02-03 08:05:08 876f4b7e
131+
│ (empty) one
132+
◆ zzzzzzzz root() 00000000
133+
[EOF]
134+
");
135+
}
136+
101137
#[test]
102138
fn test_warn_about_signing_commits_not_authored_by_me() {
103139
let test_env = TestEnvironment::default();

0 commit comments

Comments
 (0)