7 from tailslib.git import Git
13 """Convert a string representation of truth to true (1) or false (0).
14 True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
15 are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
16 'val' is anything else.
19 if val in ('y', 'yes', 't', 'true', 'on', '1'):
21 elif val in ('n', 'no', 'f', 'false', 'off', '0'):
24 raise ValueError("invalid truth value %r" % (val,))
27 def yes_no_input(prompt, default=True):
32 sys.stdout.write('%s [%s] ' % (prompt, options))
34 answer = input().lower()
39 return strtobool(answer)
41 print("Please respond with 'y' or 'n'.")
44 # Parse command-line arguments
46 parser = argparse.ArgumentParser(description='Delete merged Git branches.')
47 parser.add_argument('--repo', type=str, dest='repo',
48 help='Path to an up-to-date (bare) Tails Git repository.')
49 parser.add_argument('--remote', type=str, dest='remote', default='origin',
50 help='Push to the specified remote instead of "origin".')
51 parser.add_argument('--batch', type=bool, dest='batch',
52 nargs='?', const=True, default=False,
53 help='Assume "yes" as answer to all prompts.')
54 args = parser.parse_args()
59 pp = pprint.PrettyPrinter()
60 tailsgit = Git(args.repo)
61 branches_to_delete = tailsgit.branches_to_delete()
63 if not branches_to_delete:
64 print("No branch to delete was found.")
67 print("The following branches will be deleted:")
68 pp.pprint(sorted(branches_to_delete))
70 and not yes_no_input("Remove these branches?", default=False):
73 tailsgit.push(args.remote, [':%s' % branch for branch in branches_to_delete])