diff --git a/src/commands.rs b/src/commands.rs index 7a00077e0..200d4da00 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3484,6 +3484,14 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C ); for revision_arg in &args.revisions { let commit = workspace_command.resolve_single_rev(revision_arg)?; + if let Some(i) = commits.iter().position(|c| c == &commit) { + return Err(CommandError::UserError(format!( + r#"Revset "{}" and "{}" resolved to the same revision {}"#, + args.revisions[i], + revision_arg, + short_commit_hash(commit.id()), + ))); + } parent_ids.push(commit.id().clone()); commits.push(commit); } diff --git a/tests/test_new_command.rs b/tests/test_new_command.rs index 56c4b6b1a..9e680e7ad 100644 --- a/tests/test_new_command.rs +++ b/tests/test_new_command.rs @@ -86,6 +86,12 @@ fn test_new_merge() { // `jj merge` with less than two arguments is an error test_env.jj_cmd_cli_error(&repo_path, &["merge"]); test_env.jj_cmd_cli_error(&repo_path, &["merge", "main"]); + + // merge with non-unique revisions + let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "c34d"]); + insta::assert_snapshot!(stderr, @r###" + Error: Revset "@" and "c34d" resolved to the same revision c34d60aa3322 + "###); } fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {