def remove_merged_branches(merged_with_branch): """ Remove branches which are already merged (in master by default) Argument MERGED_WITH_BRANCH defaults to master and checks whether a branch was merged with this one """ a = App() to_remove = [] for branch_dict in a.list_branches(merged_with_branch): branch_name = branch_dict["name"] if branch_name == merged_with_branch or branch_name == branch_dict["remote_tracking"]: # don't remove self or a local copy of remote branch continue if branch_dict["merged"] == "merged": to_remove.append(branch_name) if not to_remove: print("Nothing to remove.") return print("Shall we remove these local branches?") for b in to_remove: print(f"* {b}") inp = input("Y/N? ") if inp in ("y", "Y", "yolo"): print("Removing...") for b in to_remove: a.remove_branch(b) else: print("Doing nothing, stay safe my friend.")
def list_branches(merged_with, remote): """ List git branches in current git repository """ a = App() print( tabulate( a.list_branches(merged_with=merged_with, remote=remote), tablefmt="fancy_grid", ))