From 333c348fb929d662144219360d3801fd5421bd71 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 28 Jun 2023 19:36:08 -0700 Subject: [PATCH] branch forget & delete: report if forgot/deleted multiple branches --- src/commands/branch.rs | 14 ++++++++++---- tests/test_branch_command.rs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/commands/branch.rs b/src/commands/branch.rs index 69f84a55e..adceec912 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -272,10 +272,13 @@ fn cmd_branch_delete( let names: BTreeSet = args.names.iter().cloned().chain(globbed_names).collect(); let branch_term = make_branch_term(names.iter().collect_vec().as_slice()); let mut tx = workspace_command.start_transaction(&format!("delete {branch_term}")); - for branch_name in names { - tx.mut_repo().remove_local_branch(&branch_name); + for branch_name in names.iter() { + tx.mut_repo().remove_local_branch(branch_name); } tx.finish(ui)?; + if names.len() > 1 { + writeln!(ui, "Deleted {} branches.", names.len())?; + } Ok(()) } @@ -295,10 +298,13 @@ fn cmd_branch_forget( let names: BTreeSet = args.names.iter().cloned().chain(globbed_names).collect(); let branch_term = make_branch_term(names.iter().collect_vec().as_slice()); let mut tx = workspace_command.start_transaction(&format!("forget {branch_term}")); - for branch_name in names { - tx.mut_repo().remove_branch(&branch_name); + for branch_name in names.iter() { + tx.mut_repo().remove_branch(branch_name); } tx.finish(ui)?; + if names.len() > 1 { + writeln!(ui, "Forgot {} branches.", names.len())?; + } Ok(()) } diff --git a/tests/test_branch_command.rs b/tests/test_branch_command.rs index 005a3695d..98be8a2a8 100644 --- a/tests/test_branch_command.rs +++ b/tests/test_branch_command.rs @@ -37,8 +37,10 @@ fn test_branch_multiple_names() { ◉ 000000000000 "###); - let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "foo", "bar"]); - insta::assert_snapshot!(stdout, @""); + let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "foo", "bar", "foo"]); + insta::assert_snapshot!(stdout, @r###" + Deleted 2 branches. + "###); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ 230dd059e1b0 ◉ 000000000000 @@ -87,7 +89,9 @@ fn test_branch_forget_glob() { ◉ 000000000000 "###); let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "forget", "--glob", "foo-[1-3]"]); - insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stdout, @r###" + Forgot 2 branches. + "###); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ bar-2 foo-4 230dd059e1b0 ◉ 000000000000 @@ -161,7 +165,9 @@ fn test_branch_delete_glob() { ~ "###); let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "--glob", "foo-[1-3]"]); - insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stdout, @r###" + Deleted 2 branches. + "###); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ bar-2 foo-1@origin foo-3@origin foo-4 6fbf398c2d59 │