7 from distutils.util import strtobool
8 from tailslib.git import Git
13 def yes_no_input(prompt, default=True):
18 sys.stdout.write('%s [%s] ' % (prompt, options))
20 answer = input().lower()
25 return strtobool(answer)
27 print("Please respond with 'y' or 'n'.")
30 # Parse command-line arguments
32 parser = argparse.ArgumentParser(description='Delete merged Git branches.')
33 parser.add_argument('--repo', type=str, dest='repo',
34 help='Path to an up-to-date (bare) Tails Git repository.')
35 parser.add_argument('--remote', type=str, dest='remote', default='origin',
36 help='Push to the specified remote instead of "origin".')
37 parser.add_argument('--batch', type=bool, dest='batch',
38 nargs='?', const=True, default=False,
39 help='Assume "yes" as answer to all prompts.')
40 args = parser.parse_args()
45 pp = pprint.PrettyPrinter()
46 tailsgit = Git(args.repo)
47 branches_to_delete = tailsgit.branches_to_delete()
49 if not branches_to_delete:
50 print("No branch to delete was found.")
53 print("The following branches will be deleted:")
54 pp.pprint(sorted(branches_to_delete))
56 and not yes_no_input("Remove these branches?", default=False):
59 tailsgit.push(args.remote, [':%s' % branch for branch in branches_to_delete])