2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
7 Checks out a downstream branch from the currently checked out branch. If there
8 is more than one downstream branch, then this script will prompt you to select
15 from git_common import current_branch, branches, upstream, run, hash_one
19 parser = argparse.ArgumentParser()
20 parser.add_argument('--pick',
22 'The number to pick if this command would '
24 opts = parser.parse_args(args)
27 cur = current_branch()
32 return hash_one(parent)
35 downstreams = [b for b in branches() if upfn(b) == cur]
37 return "No downstream branches"
38 elif len(downstreams) == 1:
39 run('checkout', downstreams[0], stdout=sys.stdout, stderr=sys.stderr)
41 high = len(downstreams) - 1
43 print "Please select a downstream branch"
44 for i, b in enumerate(downstreams):
45 print " %d. %s" % (i, b)
46 prompt = "Selection (0-%d)[0]: " % high
51 r = raw_input(prompt).strip() or '0'
52 if not r.isdigit() or (0 > int(r) > high):
53 print "Invalid choice."
55 run('checkout', downstreams[int(r)], stdout=sys.stdout,
60 if __name__ == '__main__':
62 sys.exit(main(sys.argv[1:]))
63 except KeyboardInterrupt: