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

cli: disallow to create new branch by "jj branch set"

Per discussion in https://github.com/martinvonz/jj/discussions/2555. I'm
okay with either way, but it's confusing if we had "branch create" and
"branch set" and both of these could create a new branch.
This commit is contained in:
Yuya Nishihara 2023-11-10 09:38:03 +09:00
parent aca2a3cf93
commit 0d21578846
3 changed files with 19 additions and 1 deletions

View file

@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The `remote_branches()` revset no longer includes branches exported to the Git * The `remote_branches()` revset no longer includes branches exported to the Git
repository (so called Git-tracking branches.) repository (so called Git-tracking branches.)
* `jj branch set` no longer creates a new branch. Use `jj branch create`
instead.
### New features ### New features
* `jj workspace add` can now take _multiple_ `--revision` arguments, which will * `jj workspace add` can now take _multiple_ `--revision` arguments, which will

View file

@ -123,7 +123,7 @@ pub struct BranchForgetArgs {
pub glob: Vec<StringPattern>, pub glob: Vec<StringPattern>,
} }
/// Update a given branch to point to a certain commit. /// Update an existing branch to point to a certain commit.
#[derive(clap::Args, Clone, Debug)] #[derive(clap::Args, Clone, Debug)]
pub struct BranchSetArgs { pub struct BranchSetArgs {
/// The branch's target revision. /// The branch's target revision.
@ -298,6 +298,15 @@ fn cmd_branch_set(
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?; workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"), ui)?;
let repo = workspace_command.repo().as_ref(); let repo = workspace_command.repo().as_ref();
let branch_names = &args.names; let branch_names = &args.names;
for name in branch_names {
let old_target = repo.view().get_local_branch(name);
if old_target.is_absent() {
return Err(user_error_with_hint(
format!("No such branch: {name}"),
"Use `jj branch create` to create it.",
));
}
}
if !args.allow_backwards if !args.allow_backwards
&& !branch_names && !branch_names
.iter() .iter()

View file

@ -98,6 +98,12 @@ fn test_branch_move() {
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo"); let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "set", "foo"]);
insta::assert_snapshot!(stderr, @r###"
Error: No such branch: foo
Hint: Use `jj branch create` to create it.
"###);
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]); let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
insta::assert_snapshot!(stderr, @""); insta::assert_snapshot!(stderr, @"");