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

cli: fix crash on "jj merge whatever root"

This commit is contained in:
Yuya Nishihara 2022-08-31 17:56:37 +09:00
parent 1cc7fc4cd9
commit c5aab9fe29
2 changed files with 10 additions and 0 deletions

View file

@ -3495,6 +3495,13 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
parent_ids.push(commit.id().clone());
commits.push(commit);
}
if parent_ids.len() >= 2
&& parent_ids.contains(workspace_command.repo().store().root_commit_id())
{
return Err(CommandError::UserError(
"Cannot merge with root revision".to_owned(),
));
}
let mut tx = workspace_command.start_transaction("new empty commit");
let merged_tree = merge_commit_trees(workspace_command.repo().as_repo_ref(), &commits);
let new_commit = CommitBuilder::for_new_commit(ui.settings(), merged_tree.id().clone())

View file

@ -92,6 +92,9 @@ fn test_new_merge() {
insta::assert_snapshot!(stderr, @r###"
Error: Revset "@" and "c34d" resolved to the same revision c34d60aa3322
"###);
// merge with root
test_env.jj_cmd_failure(&repo_path, &["new", "@", "root"]);
}
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {