cli: make it allowed to have a branch on the root commit again

Closes #1529.
This commit is contained in:
Martin von Zweigbergk 2023-09-03 14:07:15 -07:00 committed by Martin von Zweigbergk
parent f198a1e5f9
commit 2b9c9d22cf
2 changed files with 9 additions and 5 deletions

View File

@ -152,7 +152,6 @@ fn cmd_branch_create(
let target_commit =
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
workspace_command.check_rewritable(&target_commit)?;
let mut tx = workspace_command.start_transaction(&format!(
"create {} pointing to commit {}",
make_branch_term(&branch_names),
@ -183,7 +182,6 @@ fn cmd_branch_set(
let target_commit =
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
workspace_command.check_rewritable(&target_commit)?;
if !args.allow_backwards
&& !branch_names.iter().all(|branch_name| {
is_fast_forward(

View File

@ -46,14 +46,20 @@ fn test_branch_multiple_names() {
}
#[test]
fn test_branch_forbidden_at_root() {
fn test_branch_at_root() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "create", "fred", "-r=root()"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "create", "fred", "-r=root()"]);
insta::assert_snapshot!(stdout, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @r###"
Error: Cannot rewrite the root commit
Failed to export some branches:
fred
"###);
}