From c5aab9fe29aa8ad6eed7691f0fef032933b15beb Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 31 Aug 2022 17:56:37 +0900 Subject: [PATCH] cli: fix crash on "jj merge whatever root" --- src/commands.rs | 7 +++++++ tests/test_new_command.rs | 3 +++ 2 files changed, 10 insertions(+) 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 {