@cli.command()<EOL>@click.option("<STR_LIT>", "<STR_LIT>", is_flag=True, default=False)<EOL>@click.argument("<STR_LIT>")<EOL>@pass_config<EOL>def cleanup(config, searchstring, force=False):
repo = config.repo<EOL>branches_ = list(find(repo, searchstring))<EOL>if not branches_:<EOL><INDENT>error_out("<STR_LIT>")<EOL><DEDENT>elif len(branches_) > <NUM_LIT:1>:<EOL><INDENT>error_out(<EOL>"<STR_LIT>".format(<EOL>"<STR_LIT>".join(["<STR_LIT>"] + [x.name for x in branches_])<EOL>)<EOL>)<EOL><DEDENT>assert len(branches_) == <NUM_LIT:1><EOL>branch_name = branches_[<NUM_LIT:0>].name<EOL>active_branch = repo.active_branch<EOL>if branch_name == active_branch.name:<EOL><INDENT>error_out("<STR_LIT>")<EOL><DEDENT>upstream_remote = None<EOL>fork_remote = None<EOL>state = read(config.configfile)<EOL>origin_name = state.get("<STR_LIT>", "<STR_LIT>")<EOL>for remote in repo.remotes:<EOL><INDENT>if remote.name == origin_name:<EOL><INDENT>upstream_remote = remote<EOL>break<EOL><DEDENT><DEDENT>if not upstream_remote:<EOL><INDENT>error_out("<STR_LIT>".format(origin_name))<EOL><DEDENT>repo.heads.master.checkout()<EOL>upstream_remote.pull(repo.heads.master)<EOL>merged_branches = [<EOL>x.strip()<EOL>for x in repo.git.branch("<STR_LIT>").splitlines()<EOL>if x.strip() and not x.strip().startswith("<STR_LIT:*>")<EOL>]<EOL>was_merged = branch_name in merged_branches<EOL>certain = was_merged or force<EOL>if not certain:<EOL><INDENT>certain = (<EOL>input("<STR_LIT>".format(branch_name))<EOL>.lower()<EOL>.strip()<EOL>!= "<STR_LIT:n>"<EOL>)<EOL><DEDENT>if not certain:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>if was_merged:<EOL><INDENT>repo.git.branch("<STR_LIT>", branch_name)<EOL><DEDENT>else:<EOL><INDENT>repo.git.branch("<STR_LIT>", branch_name)<EOL><DEDENT>fork_remote = None<EOL>state = read(config.configfile)<EOL>for remote in repo.remotes:<EOL><INDENT>if remote.name == state.get("<STR_LIT>"):<EOL><INDENT>fork_remote = remote<EOL>break<EOL><DEDENT><DEDENT>if fork_remote:<EOL><INDENT>fork_remote.push("<STR_LIT::>" + branch_name)<EOL>info_out("<STR_LIT>")<EOL><DEDENT>
Deletes a found branch locally and remotely.