From db14f331703abbab7fc09255d5caa641077b43c4 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Thu, 4 Apr 2024 16:07:39 -0500 Subject: [PATCH] cli: add `ui.always-allow-large-revsets` option This lets users use "large" revsets in commands such as `jj rebase`, without needing the `all:` modifier. Signed-off-by: Austin Seipp Change-Id: Ica80927324f3d634413d3cc79fbc73057ccefd8a --- CHANGELOG.md | 3 +++ cli/src/cli_util.rs | 5 ++++- cli/src/config-schema.json | 5 +++++ cli/src/config/misc.toml | 2 +- cli/tests/test_rebase_command.rs | 22 ++++++++++++++++++++++ docs/config.md | 22 ++++++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90084f17c6..78796b3523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `ui.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 diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index a393fc58d8..5e3b6504d0 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -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("ui.always-allow-large-revsets")?, }; if all { for commit in expression.evaluate_to_commits()? { diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index a6bca7fffc..7d5c5363ec 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -41,6 +41,11 @@ "description": "Whether to allow initializing a repo with the native backend", "default": false }, + "always-allow-large-revsets": { + "type": "boolean", + "description": "Whether to allow large revsets to be used in all commands without the `all:` modifier", + "default": false + }, "default-command": { "type": "string", "description": "Default command to run when no explicit command is given", diff --git a/cli/src/config/misc.toml b/cli/src/config/misc.toml index 0b2e1b94db..dde689ad1c 100644 --- a/cli/src/config/misc.toml +++ b/cli/src/config/misc.toml @@ -5,11 +5,11 @@ amend = ["squash"] co = ["checkout"] unamend = ["unsquash"] - [format] tree-level-conflicts = true [ui] +always-allow-large-revsets = false diff-instructions = true paginate = "auto" pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } } diff --git a/cli/tests/test_rebase_command.rs b/cli/tests/test_rebase_command.rs index fec0f235bc..0dd41d2919 100644 --- a/cli/tests/test_rebase_command.rs +++ b/cli/tests/test_rebase_command.rs @@ -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, @""); @@ -496,6 +498,26 @@ fn test_rebase_multiple_destinations() { ◉ "###); + // undo and do it again, but with 'ui.always-allow-large-revsets' + let (_, _) = test_env.jj_cmd_ok(&repo_path, &["undo"]); + let (_, _) = test_env.jj_cmd_ok( + &repo_path, + &[ + "rebase", + "--config-toml=ui.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 diff --git a/docs/config.md b/docs/config.md index f00257c4f4..7429a833e3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -326,6 +326,28 @@ Can be customized by the `format_short_signature()` template alias. 'format_short_signature(signature)' = 'signature.username()' ``` +### 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 — a so-called "large +revset" — 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 `ui.always-allow-large-revsets` to `true`: + +```toml +ui.always-allow-large-revsets = true +``` + ## Pager The default pager is can be set via `ui.pager` or the `PAGER` environment