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

branch forget: allow forgetting deleted branches

Partially fixes #1537
This commit is contained in:
Ilya Grigoriev 2023-06-23 21:48:48 -07:00
parent 89a3f8db76
commit e41d672cc0
3 changed files with 21 additions and 20 deletions

View file

@ -142,6 +142,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
remote, just like in a non-colocated repo.
[#864](https://github.com/martinvonz/jj/issues/864)
* It is now possible to `jj branch forget` deleted branches.
[#1537](https://github.com/martinvonz/jj/issues/1537)
## [0.7.0] - 2023-02-16
### Breaking changes

View file

@ -207,7 +207,16 @@ fn cmd_branch_delete(
args: &BranchDeleteArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
validate_branch_names_exist(workspace_command.repo().view(), &args.names)?;
for branch_name in &args.names {
if workspace_command
.repo()
.view()
.get_local_branch(branch_name)
.is_none()
{
return Err(user_error(format!("No such branch: {branch_name}")));
}
}
let mut tx =
workspace_command.start_transaction(&format!("delete {}", make_branch_term(&args.names)));
for branch_name in &args.names {
@ -239,7 +248,11 @@ fn cmd_branch_forget(
let mut workspace_command = command.workspace_helper(ui)?;
let view = workspace_command.repo().view();
validate_branch_names_exist(view, &args.names)?;
for branch_name in args.names.iter() {
if view.get_branch(branch_name).is_none() {
return Err(user_error(format!("No such branch: {branch_name}")));
}
}
let globbed_names = find_globs(view, &args.glob)?;
let names: BTreeSet<String> = args.names.iter().cloned().chain(globbed_names).collect();
let branch_term = make_branch_term(names.iter().collect_vec().as_slice());
@ -353,15 +366,6 @@ fn cmd_branch_list(
Ok(())
}
fn validate_branch_names_exist(view: &View, names: &[String]) -> Result<(), CommandError> {
for branch_name in names {
if view.get_local_branch(branch_name).is_none() {
return Err(user_error(format!("No such branch: {branch_name}")));
}
}
Ok(())
}
fn is_fast_forward(repo: &dyn Repo, branch_name: &str, new_target_id: &CommitId) -> bool {
if let Some(current_target) = repo.view().get_local_branch(branch_name) {
current_target

View file

@ -314,15 +314,9 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
// ============ End of test setup ============
// BUG: Can't forget a deleted branch
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(stderr, @r###"
Error: No such branch: feature1
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1 (deleted)
@origin: 9f01a0e04879 message
"###);
// We can forget a deleted branch
test_env.jj_cmd_success(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// Can't forget a non-existent branch
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "forget", "i_do_not_exist"]);