Skip to content

Commit

Permalink
cli: make it allowed to have a branch on the root commit again
Browse files Browse the repository at this point in the history
Closes #1529.
  • Loading branch information
martinvonz committed Sep 5, 2023
1 parent f198a1e commit 2b9c9d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 0 additions & 2 deletions cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 9 additions & 3 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"###);
}

Expand Down

0 comments on commit 2b9c9d2

Please sign in to comment.