| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 Explicitly set/remove/print the merge-base for the current branch. | 7 Explicitly set/remove/print the merge-base for the current branch. |
| 8 | 8 |
| 9 This manually set merge base will be a stand-in for `git merge-base` for the | 9 This manually set merge base will be a stand-in for `git merge-base` for the |
| 10 purposes of the chromium depot_tools git extensions. Passing no arguments will | 10 purposes of the chromium depot_tools git extensions. Passing no arguments will |
| 11 just print the effective merge base for the current branch. | 11 just print the effective merge base for the current branch. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import argparse | 14 import argparse |
| 15 import sys | 15 import sys |
| 16 | 16 |
| 17 from subprocess2 import CalledProcessError | 17 from subprocess2 import CalledProcessError |
| 18 | 18 |
| 19 from git_common import remove_merge_base, manual_merge_base, current_branch | 19 from git_common import remove_merge_base, manual_merge_base, current_branch |
| 20 from git_common import get_or_create_merge_base, hash_one | 20 from git_common import get_or_create_merge_base, hash_one, upstream |
| 21 | 21 |
| 22 | 22 |
| 23 def main(argv): | 23 def main(argv): |
| 24 parser = argparse.ArgumentParser( | 24 parser = argparse.ArgumentParser( |
| 25 description=__doc__.strip().splitlines()[0], | 25 description=__doc__.strip().splitlines()[0], |
| 26 epilog=' '.join(__doc__.strip().splitlines()[1:])) | 26 epilog=' '.join(__doc__.strip().splitlines()[1:])) |
| 27 g = parser.add_mutually_exclusive_group() | 27 g = parser.add_mutually_exclusive_group() |
| 28 g.add_argument( | 28 g.add_argument( |
| 29 'merge_base', nargs='?', | 29 'merge_base', nargs='?', |
| 30 help='The new hash to use as the merge base for the current branch' | 30 help='The new hash to use as the merge base for the current branch' |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 | 44 |
| 45 if opts.merge_base: | 45 if opts.merge_base: |
| 46 try: | 46 try: |
| 47 opts.merge_base = hash_one(opts.merge_base) | 47 opts.merge_base = hash_one(opts.merge_base) |
| 48 except CalledProcessError: | 48 except CalledProcessError: |
| 49 print >> sys.stderr, ( | 49 print >> sys.stderr, ( |
| 50 'fatal: could not resolve %s as a commit' % (opts.merge_base) | 50 'fatal: could not resolve %s as a commit' % (opts.merge_base) |
| 51 ) | 51 ) |
| 52 return 1 | 52 return 1 |
| 53 | 53 |
| 54 manual_merge_base(cur, opts.merge_base) | 54 manual_merge_base(cur, opts.merge_base, upstream(cur)) |
| 55 | 55 |
| 56 ret = 0 | 56 ret = 0 |
| 57 actual = get_or_create_merge_base(cur) | 57 actual = get_or_create_merge_base(cur) |
| 58 if opts.merge_base and opts.merge_base != actual: | 58 if opts.merge_base and opts.merge_base != actual: |
| 59 ret = 1 | 59 ret = 1 |
| 60 print "Invalid merge_base %s" % opts.merge_base | 60 print "Invalid merge_base %s" % opts.merge_base |
| 61 | 61 |
| 62 print "merge_base(%s): %s" % (cur, actual) | 62 print "merge_base(%s): %s" % (cur, actual) |
| 63 | 63 |
| 64 return ret | 64 return ret |
| 65 | 65 |
| 66 | 66 |
| 67 if __name__ == '__main__': | 67 if __name__ == '__main__': |
| 68 sys.exit(main(sys.argv[1:])) | 68 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |