From 9cc536e9e07bd36ac9bd0021c6df8ffbd4c37db5 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Fri, 3 Feb 2023 22:09:35 -0800 Subject: [PATCH] Mention --allow-large-revsets in hint when one revset resolves to multiple revisions --- src/cli_util.rs | 22 +++++++++++++++++++++- tests/test_rebase_command.rs | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index 801394dc2..25459d1c7 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1419,7 +1419,9 @@ pub fn resolve_mutliple_nonempty_revsets_flag_guarded( } else { let mut commits = IndexSet::new(); for revision_str in revisions { - let commit = workspace_command.resolve_single_rev(revision_str)?; + let commit = workspace_command + .resolve_single_rev(revision_str) + .map_err(append_large_revsets_hint_if_multiple_revisions)?; let commit_hash = short_commit_hash(commit.id()); if !commits.insert(commit) { return Err(user_error(format!( @@ -1431,6 +1433,24 @@ pub fn resolve_mutliple_nonempty_revsets_flag_guarded( } } +fn append_large_revsets_hint_if_multiple_revisions(err: CommandError) -> CommandError { + match err { + CommandError::UserError { message, hint } if message.contains("more than one revision") => { + CommandError::UserError { + message, + hint: { + Some(format!( + "{old_hint}If this was intentional, specify the `--allow-large-revsets` \ + argument", + old_hint = hint.map(|h| format!("{h}\n")).unwrap_or_default() + )) + }, + } + } + _ => err, + } +} + pub fn update_working_copy( ui: &mut Ui, repo: &Arc, diff --git a/tests/test_rebase_command.rs b/tests/test_rebase_command.rs index cd5c7dfcc..f8e28d8e5 100644 --- a/tests/test_rebase_command.rs +++ b/tests/test_rebase_command.rs @@ -320,6 +320,7 @@ fn test_rebase_multiple_destinations() { Hint: The revset "b|c" resolved to these revisions: fe2e8e8b50b3 c d370aee184ba b + If this was intentional, specify the `--allow-large-revsets` argument "###); let stdout = test_env.jj_cmd_success( &repo_path,