Guest User

Untitled

a guest
Jan 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #! /usr/bin/python
  2. import subprocess
  3. import argparse
  4.  
  5.  
  6. def sub_factory(parser, names):
  7. sub = parser.add_subparsers()
  8. for name in names:
  9. subp = sub.add_parser(name)
  10. subp.add_argument('issue', type=int, help='issue number')
  11. subp.set_defaults(func=globals().get(name))
  12.  
  13.  
  14. def find_branch(issue):
  15. for x in subprocess.check_output(['git', 'branch']).split('\n'):
  16. x = x.strip().replace('* ', '')
  17. if x.startswith('#{}_'.format(issue)):
  18. return x.decode('utf-8')
  19.  
  20.  
  21. def push(branch):
  22. subprocess.check_output(['git', 'push', 'origin', branch])
  23.  
  24.  
  25. def checkout(branch):
  26. subprocess.check_output(['git', 'checkout', branch])
  27.  
  28.  
  29. if __name__ == '__main__':
  30. COMMANDS = ['push', 'checkout']
  31. parser = argparse.ArgumentParser(description='git command aliases.')
  32. sub_factory(parser, COMMANDS)
  33.  
  34. args = parser.parse_args()
  35. branch = find_branch(args.issue)
  36. args.func(branch)
Add Comment
Please, Sign In to add comment