Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: git_nav_downstream.py

Issue 225433003: Add a basic tutorial for the tools in depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@git_map
Patch Set: pylint Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_common.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Checks out a downstream branch from the currently checked out branch. If there 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 8 is more than one downstream branch, then this script will prompt you to select
9 which branch. 9 which branch.
10 """ 10 """
11 11
12 import argparse
12 import sys 13 import sys
13 14
14 from git_common import current_branch, branches, upstream, run, hash_one 15 from git_common import current_branch, branches, upstream, run_stream, hash_one
15 16
16 17
17 def main(argv): 18 def main(args):
18 assert len(argv) == 1, "No arguments expected" 19 parser = argparse.ArgumentParser()
20 parser.add_argument('--pick',
21 help=(
22 'The number to pick if this command would '
23 'prompt'))
24 opts = parser.parse_args(args)
25
19 upfn = upstream 26 upfn = upstream
20 cur = current_branch() 27 cur = current_branch()
21 if cur == 'HEAD': 28 if cur == 'HEAD':
22 def _upfn(b): 29 def _upfn(b):
23 parent = upstream(b) 30 parent = upstream(b)
24 if parent: 31 if parent:
25 return hash_one(parent) 32 return hash_one(parent)
26 upfn = _upfn 33 upfn = _upfn
27 cur = hash_one(cur) 34 cur = hash_one(cur)
28 downstreams = [b for b in branches() if upfn(b) == cur] 35 downstreams = [b for b in branches() if upfn(b) == cur]
29 if not downstreams: 36 if not downstreams:
30 return "No downstream branches" 37 return "No downstream branches"
31 elif len(downstreams) == 1: 38 elif len(downstreams) == 1:
32 run('checkout', downstreams[0]) 39 run_stream('checkout', downstreams[0], stdout=sys.stdout, stderr=sys.stderr)
33 else: 40 else:
34 high = len(downstreams) - 1 41 high = len(downstreams) - 1
35 print
36 while True: 42 while True:
37 print "Please select a downstream branch" 43 print "Please select a downstream branch"
38 for i, b in enumerate(downstreams): 44 for i, b in enumerate(downstreams):
39 print " %d. %s" % (i, b) 45 print " %d. %s" % (i, b)
40 r = raw_input("Selection (0-%d)[0]: " % high).strip() or '0' 46 prompt = "Selection (0-%d)[0]: " % high
47 r = opts.pick
48 if r:
49 print prompt + r
50 else:
51 r = raw_input(prompt).strip() or '0'
41 if not r.isdigit() or (0 > int(r) > high): 52 if not r.isdigit() or (0 > int(r) > high):
42 print "Invalid choice." 53 print "Invalid choice."
43 else: 54 else:
44 run('checkout', downstreams[int(r)]) 55 run_stream('checkout', downstreams[int(r)], stdout=sys.stdout,
56 stderr=sys.stderr)
45 break 57 break
46 58
47 59
48 if __name__ == '__main__': 60 if __name__ == '__main__':
49 sys.exit(main(sys.argv)) 61 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « git_common.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698