From c13b5ae50ecf79ffe8f359f32078a3b9751b9e0d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 26 Oct 2021 06:06:33 -0700 Subject: [PATCH] cli: make `jj branch --delete/--forget` error out if branch doesn't exist --- src/commands.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index 3e75313ec..0330441ee 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2871,10 +2871,26 @@ fn cmd_branch(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result let mut repo_command = command.repo_helper(ui)?.rebase_descendants(false); let branch_name = args.value_of("name").unwrap(); if args.is_present("delete") { + if repo_command + .repo() + .view() + .get_local_branch(branch_name) + .is_none() + { + return Err(CommandError::UserError("No such branch".to_string())); + } let mut tx = repo_command.start_transaction(&format!("delete branch {}", branch_name)); tx.mut_repo().remove_local_branch(branch_name); repo_command.finish_transaction(ui, tx)?; } else if args.is_present("forget") { + if repo_command + .repo() + .view() + .get_local_branch(branch_name) + .is_none() + { + return Err(CommandError::UserError("No such branch".to_string())); + } let mut tx = repo_command.start_transaction(&format!("forget branch {}", branch_name)); tx.mut_repo().remove_branch(branch_name); repo_command.finish_transaction(ui, tx)?;