ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: error out if "new" parent revisions aren't unique

If more than one parents are specified, the user would expect a merge
commit.
This commit is contained in:
Yuya Nishihara 2022-08-31 16:41:08 +09:00
parent 3a46623446
commit 1cc7fc4cd9
2 changed files with 14 additions and 0 deletions

View file

@ -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);
}

View file

@ -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 {