Skip to content

Commit

Permalink
cli: add revsets.always-allow-large-revsets option
Browse files Browse the repository at this point in the history
This lets users use "large" revsets in commands such as `jj rebase`, without
needing the `all:` modifier.

Signed-off-by: Austin Seipp <[email protected]>
Change-Id: Ica80927324f3d634413d3cc79fbc73057ccefd8a
  • Loading branch information
thoughtpolice committed Apr 4, 2024
1 parent 2cf1c34 commit fbc57c7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Commit objects in templates now have a `mine() -> Boolean` method analog to the same function in revsets.
It evaluates to true if the email of the commit author matches the current `user.email`.

* A new config option `revsets.always-allow-large-revsets` has been added to
allow large revsets expressions in some commands, without the `all:` prefix.

### Fixed bugs

## [0.16.0] - 2024-04-03
Expand Down
5 changes: 4 additions & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,10 @@ impl WorkspaceCommandHelper {
let (expression, modifier) = self.parse_revset_with_modifier(revision_arg)?;
let all = match modifier {
Some(RevsetModifier::All) => true,
None => false,
None => self
.settings
.config()
.get_bool("revsets.always-allow-large-revsets")?,
};
if all {
for commit in expression.evaluate_to_commits()? {
Expand Down
5 changes: 5 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@
"type": "string",
"description": "Revisions to give shorter change and commit IDs to",
"default": "<revsets.log>"
},
"always-allow-large-revsets": {
"type": "boolean",
"description": "Whether to allow large revsets to be used in all commands without the `all:` modifier",
"default": false
}
},
"additionalProperties": {
Expand Down
2 changes: 2 additions & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ amend = ["squash"]
co = ["checkout"]
unamend = ["unsquash"]

[revsets]
always-allow-large-revsets = false

[format]
tree-level-conflicts = true
Expand Down
22 changes: 22 additions & 0 deletions cli/tests/test_rebase_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ fn test_rebase_multiple_destinations() {
zsuskuln d370aee1 b | b
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:b|c').
"###);

// try with 'all:', and succeed
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "a", "-d", "all:b|c"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
Expand All @@ -496,6 +498,26 @@ fn test_rebase_multiple_destinations() {
"###);

// undo and do it again, but with 'revsets.always-allow-large-revsets'
let (_, _) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (_, _) = test_env.jj_cmd_ok(
&repo_path,
&[
"rebase",
"--config-toml=revsets.always-allow-large-revsets=true",
"-r=a",
"-d=b|c",
],
);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ a
├─╮
│ ◉ b
@ │ c
├─╯
"###);

let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-r", "a", "-d", "b", "-d", "b"]);
insta::assert_snapshot!(stderr, @r###"
Error: More than one revset resolved to revision d370aee184ba
Expand Down
24 changes: 24 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,30 @@ executable on your system](https://facebook.github.io/watchman/docs/install).

Debugging commands are available under `jj debug watchman`.

## Revset behavior

### Allow "large" revsets by default

Certain commands (such as `jj rebase`) can take multiple revset arguments, and
each of these may resolve to one-or-many revisions. By default, `jj` will not
allow revsets that resolve to more than one revision &mdash; a so-called "large
revset" &mdash; and will ask you to confirm that you want to proceed by
prefixing it with the `all:` modifier.

For instance, to add a new parent `abc` to the commit `xyz`, you may use `jj
rebase`:

```
jj rebase -r xyz -d "all:xyz-" -d "abc"
```

`jj` requires the `all:` prefix for the above command. However, you may disable
this behavior by setting `revsets.always-allow-large-revsets` to `true`:

```toml
revsets.always-allow-large-revsets = true
```

## Ways to specify `jj` config: details

### User config file
Expand Down

0 comments on commit fbc57c7

Please sign in to comment.