Add a tutorial / walkthrough for pure-git workflow.
TBR=agable@chromium.org, szager@chromium.org
BUG=261743
Review URL: https://codereview.chromium.org/225433003
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@263164 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_nav_downstream.py b/git_nav_downstream.py
index 4d8b823..bce850e 100755
--- a/git_nav_downstream.py
+++ b/git_nav_downstream.py
@@ -9,13 +9,20 @@
which branch.
"""
+import argparse
import sys
-from git_common import current_branch, branches, upstream, run, hash_one
+from git_common import current_branch, branches, upstream, run_stream, hash_one
-def main(argv):
- assert len(argv) == 1, "No arguments expected"
+def main(args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--pick',
+ help=(
+ 'The number to pick if this command would '
+ 'prompt'))
+ opts = parser.parse_args(args)
+
upfn = upstream
cur = current_branch()
if cur == 'HEAD':
@@ -29,21 +36,26 @@
if not downstreams:
return "No downstream branches"
elif len(downstreams) == 1:
- run('checkout', downstreams[0])
+ run_stream('checkout', downstreams[0], stdout=sys.stdout, stderr=sys.stderr)
else:
high = len(downstreams) - 1
- print
while True:
print "Please select a downstream branch"
for i, b in enumerate(downstreams):
print " %d. %s" % (i, b)
- r = raw_input("Selection (0-%d)[0]: " % high).strip() or '0'
+ prompt = "Selection (0-%d)[0]: " % high
+ r = opts.pick
+ if r:
+ print prompt + r
+ else:
+ r = raw_input(prompt).strip() or '0'
if not r.isdigit() or (0 > int(r) > high):
print "Invalid choice."
else:
- run('checkout', downstreams[int(r)])
+ run_stream('checkout', downstreams[int(r)], stdout=sys.stdout,
+ stderr=sys.stderr)
break
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main(sys.argv[1:]))