Skip to content

Commit

Permalink
cli: don't silently omit root parent by "jj new --insert-before"
Browse files Browse the repository at this point in the history
Spotted by Benjamin Tan.
  • Loading branch information
yuja committed Mar 30, 2024
1 parent 3b692b4 commit 98fefce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
8 changes: 1 addition & 7 deletions cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,11 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.",
short_commit_hash(&commit_id),
)));
}
let mut new_parents_commits: Vec<Commit> = new_parents
let new_parents_commits: Vec<Commit> = new_parents
.evaluate_programmatic(tx.repo())?
.iter()
.commits(tx.repo().store())
.try_collect()?;
// The git backend does not support creating merge commits involving the root
// commit.
if new_parents_commits.len() > 1 {
let root_commit = tx.repo().store().root_commit();
new_parents_commits.retain(|c| c != &root_commit);
}
let merged_tree = merge_commit_trees(tx.repo(), &new_parents_commits)?;
let new_parents_commit_id = new_parents_commits.iter().map(|c| c.id().clone()).collect();
new_commit = tx
Expand Down
22 changes: 3 additions & 19 deletions cli/tests/test_new_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,26 +417,10 @@ fn test_new_insert_before_no_root_merge() {
◉ root
"###);

let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-before", "-m", "G", "B", "D"]);
insta::assert_snapshot!(stdout, @"");
let stderr =
test_env.jj_cmd_failure(&repo_path, &["new", "--insert-before", "-m", "G", "B", "D"]);
insta::assert_snapshot!(stderr, @r###"
Rebased 4 descendant commits
Working copy now at: kxryzmor bf9fc493 (empty) G
Parent commit : qpvuntsm 65b1ef43 A | (empty) A
"###);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
◉ F
├─╮
│ ◉ E
◉ │ D
│ │ ◉ C
│ │ ◉ B
├───╯
@ │ G
◉ │ A
├─╯
◉ root
Error: The Git backend does not support creating merge commits with the root commit as one of the parents.
"###);
}

Expand Down

0 comments on commit 98fefce

Please sign in to comment.