Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/local/bin/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 | |
| 6 import argparse | |
| 7 import sys | |
| 8 | |
| 9 from git_common import run, root, set_config, get_or_create_merge_base | |
| 10 | |
| 11 | |
| 12 def main(): | |
| 13 parser = argparse.ArgumentParser( | |
| 14 formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
| 15 ) | |
| 16 parser.add_argument('branch_name') | |
| 17 g = parser.add_mutually_exclusive_group() | |
| 18 g.add_argument('--upstream_current', action='store_true', | |
| 19 help='set upstream branch to current branch.') | |
| 20 g.add_argument('--upstream', metavar='REF', default=root(), | |
| 21 help='upstream branch to track.') | |
| 22 | |
| 23 parser.add_argument( | |
| 24 '--lkgr', action='store_const', const=('.', 'refs/tags/lkgr'), | |
|
agable
2014/03/21 01:14:21
indent +4
iannucci
2014/03/22 04:17:35
Done.
| |
| 25 dest='basis_ref', help='set basis ref for new branch to lkgr.') | |
| 26 | |
| 27 opts = parser.parse_args() | |
| 28 | |
| 29 if opts.upstream_current: | |
| 30 if opts.basis_ref: | |
| 31 parser.error('Cannot specify basis_ref with upstream_current.') | |
| 32 run('checkout', '--track', '-b', opts.branch_name) | |
| 33 else: | |
| 34 if opts.basis_ref: | |
|
agable
2014/03/21 01:14:21
You implemented a general approach to tracking tag
iannucci
2014/03/22 04:17:35
Done.
| |
| 35 # TODO(iannucci): ensure that basis_ref is an ancestor of HEAD? | |
| 36 run('checkout', '--no-track', '-b', opts.branch_name, opts.basis_ref) | |
| 37 run('branch', '-u', opts.upstream) | |
| 38 remote, merge = opts.basis_ref | |
| 39 set_config('branch.%s.remote', remote) | |
| 40 set_config('branch.%s.merge', merge) | |
| 41 else: | |
| 42 # TODO(iannucci): Detect unclean workdir then stash+pop if we need to | |
| 43 # teleport to a conflicting portion of history? | |
| 44 run('checkout', '--track', opts.upstream, '-b', opts.branch_name) | |
| 45 | |
| 46 get_or_create_merge_base(opts.branch_name) | |
| 47 | |
| 48 | |
| 49 if __name__ == '__main__': | |
| 50 sys.exit(main()) | |
| OLD | NEW |