OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 """ |
| 3 Checks out a downstream branch from the currently checked out branch. If there |
| 4 is more than one downstream branch, then this script will prompt you to select |
| 5 which branch. |
| 6 """ |
| 7 import sys |
| 8 |
| 9 from git_common import current_branch, branches, upstream, run, hash_one |
| 10 |
| 11 |
| 12 def main(argv): |
| 13 assert len(argv) == 1, "No arguments expected" |
| 14 upfn = upstream |
| 15 cur = current_branch() |
| 16 if cur == 'HEAD': |
| 17 upfn = lambda b: hash_one(upstream(b)) |
| 18 cur = hash_one(cur) |
| 19 downstreams = [b for b in branches() if upfn(b) == cur] |
| 20 if not downstreams: |
| 21 return "No downstream branches" |
| 22 elif len(downstreams) == 1: |
| 23 run('checkout', downstreams[0]) |
| 24 else: |
| 25 high = len(downstreams) - 1 |
| 26 print |
| 27 while True: |
| 28 print "Please select a downstream branch" |
| 29 for i, b in enumerate(downstreams): |
| 30 print " %d. %s" % (i, b) |
| 31 r = raw_input("Selection (0-%d)[0]: " % high).strip() or '0' |
| 32 if not r.isdigit() or (0 > int(r) > high): |
| 33 print "Invalid choice." |
| 34 else: |
| 35 run('checkout', downstreams[int(r)]) |
| 36 break |
| 37 |
| 38 |
| 39 if __name__ == '__main__': |
| 40 sys.exit(main(sys.argv)) |
OLD | NEW |