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

cli: make jj branch --delete/--forget error out if branch doesn't exist

This commit is contained in:
Martin von Zweigbergk 2021-10-26 06:06:33 -07:00
parent 9abee0096f
commit c13b5ae50e

View file

@ -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)?;