Chromium Code Reviews| Index: git_mark_merge_base.py |
| diff --git a/git_mark_merge_base.py b/git_mark_merge_base.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..b4f8c7479e08f8e58a04124d0d56e95109cd7082 |
| --- /dev/null |
| +++ b/git_mark_merge_base.py |
| @@ -0,0 +1,69 @@ |
| +#!/usr/bin/env 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. |
| + |
| +# Weird spaces at the front are due to a formatting constraint of argparse. |
| +""" |
| +Explicitly set/remove/print the merge-base for the current branch. |
| + |
| +This manually set merge base will be a stand-in for `git merge-base` for the |
| + purposes of the chromium depot_tools git extensions. Passing no arguments will |
| + just print the effective merge base for the current branch. |
| +""" |
| + |
| +import argparse |
| +import sys |
| + |
| +from subprocess2 import CalledProcessError |
| + |
| +from git_common import remove_merge_base, manual_merge_base, current_branch |
| +from git_common import get_or_create_merge_base, hash_one |
| + |
| + |
| +def main(argv): |
| + parser = argparse.ArgumentParser( |
| + description=__doc__.strip().splitlines()[0], |
| + epilog=''.join(__doc__.strip().splitlines()[1:])) |
|
agable
2014/03/25 19:37:23
Do ' '.join(blah) and get rid of the leading space
iannucci
2014/03/26 01:39:49
Derpdone
|
| + g = parser.add_mutually_exclusive_group() |
| + g.add_argument( |
| + 'merge_base', nargs='?', |
| + help='The new hash to use as the merge base for the current branch' |
| + ) |
| + g.add_argument('--delete', '-d', action='store_true', |
| + help='Remove the set mark.') |
| + opts = parser.parse_args(argv) |
| + |
| + cur = current_branch() |
| + |
| + if opts.delete: |
| + try: |
| + remove_merge_base(cur) |
| + except CalledProcessError: |
| + print "No merge base currently exists for %s." % cur |
| + return 0 |
| + |
| + if opts.merge_base: |
| + try: |
| + opts.merge_base = hash_one(opts.merge_base) |
| + except CalledProcessError: |
| + print >> sys.stderr, ( |
| + 'fatal: could not resolve %s as a commit' % (opts.merge_base) |
| + ) |
| + return 1 |
| + |
| + manual_merge_base(cur, opts.merge_base) |
| + |
| + ret = 0 |
| + actual = get_or_create_merge_base(cur) |
| + if opts.merge_base and opts.merge_base != actual: |
| + ret = 1 |
| + print "Invalid merge_base %s" % opts.merge_base |
| + |
| + print "merge_base(%s): %s" % (cur, actual) |
| + |
| + return ret |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |