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

cli: jj duplicate should refuse to duplicate only the root commit

Once we add support for immutable commits, `jj duplicate` should be
allowed to create duplicate of them. The reason it can't duplicate the
root commit is that it would mean there would be multiple root
commits, which would break the invariant that the single root commit
is the only root commit (and the backends refuse to write a commit
without parents). So let's have `jj duplicate` check specifically that
the user doesn't try to duplicate the root commit instead.
This commit is contained in:
Martin von Zweigbergk 2023-09-03 14:00:25 -07:00 committed by Martin von Zweigbergk
parent 551abee1d6
commit 3fbfd17182
2 changed files with 6 additions and 4 deletions

View file

@ -2173,10 +2173,12 @@ fn cmd_duplicate(
let mut workspace_command = command.workspace_helper(ui)?;
let to_duplicate: IndexSet<Commit> =
resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?;
to_duplicate
if to_duplicate
.iter()
.map(|commit| workspace_command.check_rewritable(commit))
.try_collect()?;
.any(|commit| commit.id() == workspace_command.repo().store().root_commit_id())
{
return Err(user_error("Cannot duplicate the root commit"));
}
let mut duplicated_old_to_new: IndexMap<Commit, Commit> = IndexMap::new();
let mut tx = workspace_command

View file

@ -51,7 +51,7 @@ fn test_duplicate() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["duplicate", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Error: Cannot rewrite the root commit
Error: Cannot duplicate the root commit
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "a"]);