Skip to content

Commit

Permalink
cli: don't check duplicates in revisions prefixed with "all:"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuja committed Apr 2, 2024
1 parent c3fa13e commit 5d09234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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!(
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/test_new_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()"]);
Expand Down

0 comments on commit 5d09234

Please sign in to comment.