cli: don't silently omit root parent by "jj new --insert-before"

Spotted by Benjamin Tan.
This commit is contained in:
Yuya Nishihara 2024-03-30 16:42:36 +09:00
parent 73b60903ce
commit 05242c95cd
2 changed files with 4 additions and 26 deletions

View file

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

View file

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