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

Side by Side Diff: git_nav_downstream.py

Issue 196433003: Fix git_nav_downstream.py when origin/master is checked out. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Also add a * on origin/master when its checked out Created 6 years, 9 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_map_branches.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.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
2 """ 6 """
3 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
4 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
5 which branch. 9 which branch.
6 """ 10 """
7 import sys 11 import sys
8 12
9 from git_common import current_branch, branches, upstream, run, hash_one 13 from git_common import current_branch, branches, upstream, run, hash_one
10 14
11 15
12 def main(argv): 16 def main(argv):
13 assert len(argv) == 1, "No arguments expected" 17 assert len(argv) == 1, "No arguments expected"
14 upfn = upstream 18 upfn = upstream
15 cur = current_branch() 19 cur = current_branch()
16 if cur == 'HEAD': 20 if cur == 'HEAD':
17 upfn = lambda b: hash_one(upstream(b)) 21 def _upfn(b):
22 parent = upstream(b)
23 if parent:
24 return hash_one(parent)
25 upfn = _upfn
18 cur = hash_one(cur) 26 cur = hash_one(cur)
19 downstreams = [b for b in branches() if upfn(b) == cur] 27 downstreams = [b for b in branches() if upfn(b) == cur]
20 if not downstreams: 28 if not downstreams:
21 return "No downstream branches" 29 return "No downstream branches"
22 elif len(downstreams) == 1: 30 elif len(downstreams) == 1:
23 run('checkout', downstreams[0]) 31 run('checkout', downstreams[0])
24 else: 32 else:
25 high = len(downstreams) - 1 33 high = len(downstreams) - 1
26 print 34 print
27 while True: 35 while True:
28 print "Please select a downstream branch" 36 print "Please select a downstream branch"
29 for i, b in enumerate(downstreams): 37 for i, b in enumerate(downstreams):
30 print " %d. %s" % (i, b) 38 print " %d. %s" % (i, b)
31 r = raw_input("Selection (0-%d)[0]: " % high).strip() or '0' 39 r = raw_input("Selection (0-%d)[0]: " % high).strip() or '0'
32 if not r.isdigit() or (0 > int(r) > high): 40 if not r.isdigit() or (0 > int(r) > high):
33 print "Invalid choice." 41 print "Invalid choice."
34 else: 42 else:
35 run('checkout', downstreams[int(r)]) 43 run('checkout', downstreams[int(r)])
36 break 44 break
37 45
38 46
39 if __name__ == '__main__': 47 if __name__ == '__main__':
40 sys.exit(main(sys.argv)) 48 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « git_map_branches.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698