From db15571eca63ba074fb0014ddafb6a211c6c6eb5 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 30 Mar 2024 16:48:09 +0900 Subject: [PATCH] cli: simplify check for non-empty revisions with/without "all:" If "all:" is specified, an empty set should be allowed within that expression. So the additional check we need here is to ensure that the resulting set is not empty. --- cli/src/cli_util.rs | 9 +++++---- cli/src/commands/new.rs | 4 ---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index be61f4ad1..1c37c99fb 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1658,9 +1658,6 @@ pub fn resolve_multiple_nonempty_revsets_default_single( let mut all_commits = IndexSet::new(); for revision_str in revisions { let commits = workspace_command.resolve_revset_default_single(revision_str)?; - if commits.is_empty() { - return Err(user_error("Empty revision set")); - } for commit in commits { let commit_hash = short_commit_hash(commit.id()); if !all_commits.insert(commit) { @@ -1670,7 +1667,11 @@ pub fn resolve_multiple_nonempty_revsets_default_single( } } } - Ok(all_commits) + if all_commits.is_empty() { + Err(user_error("Empty revision set")) + } else { + Ok(all_commits) + } } pub fn update_working_copy( diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs index eec01cd4d..1b10eca86 100644 --- a/cli/src/commands/new.rs +++ b/cli/src/commands/new.rs @@ -96,10 +96,6 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.", )); } let mut workspace_command = command.workspace_helper(ui)?; - assert!( - !args.revisions.is_empty(), - "expected a non-empty list from clap" - ); let target_commits = resolve_multiple_nonempty_revsets_default_single(&workspace_command, &args.revisions)? .into_iter()