Chromium Code Reviews| Index: git_new_branch.py |
| diff --git a/git_new_branch.py b/git_new_branch.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..1f93e07c9362401d40572deb0e4c36269adb34c0 |
| --- /dev/null |
| +++ b/git_new_branch.py |
| @@ -0,0 +1,50 @@ |
| +#!/usr/local/bin/python |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import argparse |
| +import sys |
| + |
| +from git_common import run, root, set_config, get_or_create_merge_base |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser( |
| + formatter_class=argparse.ArgumentDefaultsHelpFormatter |
| + ) |
| + parser.add_argument('branch_name') |
| + g = parser.add_mutually_exclusive_group() |
| + g.add_argument('--upstream_current', action='store_true', |
| + help='set upstream branch to current branch.') |
| + g.add_argument('--upstream', metavar='REF', default=root(), |
| + help='upstream branch to track.') |
| + |
| + parser.add_argument( |
| + '--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.
|
| + dest='basis_ref', help='set basis ref for new branch to lkgr.') |
| + |
| + opts = parser.parse_args() |
| + |
| + if opts.upstream_current: |
| + if opts.basis_ref: |
| + parser.error('Cannot specify basis_ref with upstream_current.') |
| + run('checkout', '--track', '-b', opts.branch_name) |
| + else: |
| + 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.
|
| + # TODO(iannucci): ensure that basis_ref is an ancestor of HEAD? |
| + run('checkout', '--no-track', '-b', opts.branch_name, opts.basis_ref) |
| + run('branch', '-u', opts.upstream) |
| + remote, merge = opts.basis_ref |
| + set_config('branch.%s.remote', remote) |
| + set_config('branch.%s.merge', merge) |
| + else: |
| + # TODO(iannucci): Detect unclean workdir then stash+pop if we need to |
| + # teleport to a conflicting portion of history? |
| + run('checkout', '--track', opts.upstream, '-b', opts.branch_name) |
| + |
| + get_or_create_merge_base(opts.branch_name) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |