diff --git a/src/cli_util.rs b/src/cli_util.rs index 2e9245463..f1be1ba92 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1409,15 +1409,15 @@ pub fn resolve_multiple_nonempty_revsets( Ok(acc) } -pub fn resolve_base_revs( +pub fn resolve_mutliple_nonempty_revsets_flag_guarded( workspace_command: &WorkspaceCommandHelper, revisions: &[RevisionArg], allow_plural_revsets: bool, ) -> Result, CommandError> { - let mut commits = IndexSet::new(); if allow_plural_revsets { - commits = resolve_multiple_nonempty_revsets(revisions, workspace_command)?; + resolve_multiple_nonempty_revsets(revisions, workspace_command) } else { + let mut commits = IndexSet::new(); for revision_str in revisions { let commit = workspace_command.resolve_single_rev(revision_str)?; let commit_hash = short_commit_hash(commit.id()); @@ -1427,8 +1427,22 @@ pub fn resolve_base_revs( ))); } } + Ok(commits) } +} +/// Resolves revsets into revisions to rebase onto. These revisions don't have +/// to be rewriteable. +pub fn resolve_destination_revs( + workspace_command: &WorkspaceCommandHelper, + revisions: &[RevisionArg], + allow_plural_revsets: bool, +) -> Result, CommandError> { + let commits = resolve_mutliple_nonempty_revsets_flag_guarded( + workspace_command, + revisions, + allow_plural_revsets, + )?; let root_commit_id = workspace_command.repo().store().root_commit_id(); if commits.len() >= 2 && commits.iter().any(|c| c.id() == root_commit_id) { Err(user_error("Cannot merge with root revision")) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3f786aa3b..908fab7d6 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -45,7 +45,7 @@ use maplit::{hashmap, hashset}; use pest::Parser; use crate::cli_util::{ - self, check_stale_working_copy, print_checkout_stats, resolve_base_revs, + self, check_stale_working_copy, print_checkout_stats, resolve_destination_revs, resolve_multiple_nonempty_revsets, run_ui_editor, serialize_config_value, short_commit_hash, user_error, user_error_with_hint, Args, CommandError, CommandHelper, DescriptionArg, RevisionArg, WorkspaceCommandHelper, DESCRIPTION_PLACEHOLDER_TEMPLATE, @@ -2003,7 +2003,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C !args.revisions.is_empty(), "expected a non-empty list from clap" ); - let commits = resolve_base_revs( + let commits = resolve_destination_revs( &workspace_command, &args.revisions, args.allow_large_revsets, @@ -2698,7 +2698,7 @@ fn cmd_merge(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), fn cmd_rebase(ui: &mut Ui, command: &CommandHelper, args: &RebaseArgs) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let new_parents = resolve_base_revs( + let new_parents = resolve_destination_revs( &workspace_command, &args.destination, args.allow_large_revsets,