From 2b9c9d22cf2123d12f16d29c641aedd02e5eb7b2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 3 Sep 2023 14:07:15 -0700 Subject: [PATCH] cli: make it allowed to have a branch on the root commit again Closes #1529. --- cli/src/commands/branch.rs | 2 -- cli/tests/test_branch_command.rs | 12 +++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cli/src/commands/branch.rs b/cli/src/commands/branch.rs index ea5ba7673a..0ce017bf49 100644 --- a/cli/src/commands/branch.rs +++ b/cli/src/commands/branch.rs @@ -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( diff --git a/cli/tests/test_branch_command.rs b/cli/tests/test_branch_command.rs index 1df245e0b4..b655dbdcd8 100644 --- a/cli/tests/test_branch_command.rs +++ b/cli/tests/test_branch_command.rs @@ -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 "###); }