forked from mirrors/jj
Issue warning if renaming branch with a remote tracking branch.
This commit is contained in:
parent
5ad7b2bc08
commit
08d1809dc1
3 changed files with 45 additions and 7 deletions
|
@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
* New `jj op abandon` command is added to clean up the operation history. If GC
|
||||
is implemented, Git refs and commit objects can be compacted.
|
||||
|
||||
* `jj branch rename` will now warn if the renamed branch has a remote branch, since
|
||||
those will have to be manually renamed outside of `jj`.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
|
||||
|
|
|
@ -350,6 +350,19 @@ fn cmd_branch_rename(
|
|||
return Err(user_error(format!("Branch already exists: {new_branch}")));
|
||||
}
|
||||
|
||||
if view
|
||||
.remote_branches_matching(
|
||||
&StringPattern::exact(old_branch),
|
||||
&StringPattern::everything(),
|
||||
)
|
||||
.any(|(_, remote_ref)| remote_ref.is_tracking())
|
||||
{
|
||||
writeln!(
|
||||
ui.warning(),
|
||||
"warning: Branch {old_branch} has remote branches which will not be renamed"
|
||||
)?;
|
||||
}
|
||||
|
||||
let mut tx = workspace_command.start_transaction();
|
||||
tx.mut_repo()
|
||||
.set_local_branch_target(new_branch, ref_target);
|
||||
|
@ -363,6 +376,7 @@ fn cmd_branch_rename(
|
|||
make_branch_term(&[new_branch]),
|
||||
),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -195,20 +195,41 @@ fn test_branch_rename() {
|
|||
test_env.jj_cmd_ok(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", "rename", "foo", "bar"]);
|
||||
// Set up remote
|
||||
let git_repo_path = test_env.env_root().join("git-repo");
|
||||
git2::Repository::init_bare(git_repo_path).unwrap();
|
||||
test_env.jj_cmd_ok(
|
||||
&repo_path,
|
||||
&["git", "remote", "add", "origin", "../git-repo"],
|
||||
);
|
||||
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "rename", "bnoexist", "blocal"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: No such branch: foo
|
||||
Error: No such branch: bnoexist
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
|
||||
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "rename", "foo", "bar"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-0"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "blocal"]);
|
||||
let (_stdout, stderr) =
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "rename", "blocal", "blocal1"]);
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
|
||||
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "conflictfoo"]);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "rename", "bar", "conflictfoo"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-1"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bexist"]);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "rename", "blocal1", "bexist"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Branch already exists: conflictfoo
|
||||
Error: Branch already exists: bexist
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-2"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bremote"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["git", "push", "-b=bremote"]);
|
||||
let (_stdout, stderr) =
|
||||
test_env.jj_cmd_ok(&repo_path, &["branch", "rename", "bremote", "bremote2"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
warning: Branch bremote has remote branches which will not be renamed
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue