diff --git a/src/commands.rs b/src/commands.rs index 200d4da00..f3d950907 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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()) diff --git a/tests/test_new_command.rs b/tests/test_new_command.rs index 9e680e7ad..4b19e488c 100644 --- a/tests/test_new_command.rs +++ b/tests/test_new_command.rs @@ -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 {