cli: don't check duplicates in revisions prefixed with "all:"

Since "all:" implies that the user doesn't care about the order of the
revisions within that argument, it should be okay if two "all:" sets overlapped.
This commit is contained in:
Yuya Nishihara 2024-03-31 13:41:58 +09:00
parent c3fa13e761
commit 5d09234839
2 changed files with 11 additions and 5 deletions

View file

@ -772,8 +772,10 @@ impl WorkspaceCommandHelper {
let mut all_commits = IndexSet::new();
for revision_str in revision_args {
let (expression, all) = self.parse_revset_with_all_prefix(revision_str)?;
let commits = if all {
expression.evaluate_to_commits()?.try_collect()?
if all {
for commit in expression.evaluate_to_commits()? {
all_commits.insert(commit?);
}
} else {
let should_hint_about_all_prefix = true;
let commit = revset_util::evaluate_revset_to_single_commit(
@ -782,9 +784,6 @@ impl WorkspaceCommandHelper {
|| self.commit_summary_template(),
should_hint_about_all_prefix,
)?;
vec![commit]
};
for commit in commits {
let commit_hash = short_commit_hash(commit.id());
if !all_commits.insert(commit) {
return Err(user_error(format!(

View file

@ -137,6 +137,13 @@ fn test_new_merge() {
insta::assert_snapshot!(stderr, @r###"
Error: More than one revset resolved to revision 3a44e52b073c
"###);
// if prefixed with all:, duplicates are allowed
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["new", "@", "all:visible_heads()"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Working copy now at: xznxytkn dddeb489 (empty) (no description set)
Parent commit : wqnwkozp 3a44e52b (empty) (no description set)
"###);
// merge with root
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "root()"]);