OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env 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 # Weird spaces at the front are due to a formatting constraint of argparse. | |
7 """ | |
8 Explicitly set/remove/print the merge-base for the current branch. | |
9 | |
10 This manually set merge base will be a stand-in for `git merge-base` for the | |
11 purposes of the chromium depot_tools git extensions. Passing no arguments will | |
12 just print the effective merge base for the current branch. | |
13 """ | |
14 | |
15 import argparse | |
16 import sys | |
17 | |
18 from subprocess2 import CalledProcessError | |
19 | |
20 from git_common import remove_merge_base, manual_merge_base, current_branch | |
21 from git_common import get_or_create_merge_base, hash_one | |
22 | |
23 | |
24 def main(argv): | |
25 parser = argparse.ArgumentParser( | |
26 description=__doc__.strip().splitlines()[0], | |
27 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
| |
28 g = parser.add_mutually_exclusive_group() | |
29 g.add_argument( | |
30 'merge_base', nargs='?', | |
31 help='The new hash to use as the merge base for the current branch' | |
32 ) | |
33 g.add_argument('--delete', '-d', action='store_true', | |
34 help='Remove the set mark.') | |
35 opts = parser.parse_args(argv) | |
36 | |
37 cur = current_branch() | |
38 | |
39 if opts.delete: | |
40 try: | |
41 remove_merge_base(cur) | |
42 except CalledProcessError: | |
43 print "No merge base currently exists for %s." % cur | |
44 return 0 | |
45 | |
46 if opts.merge_base: | |
47 try: | |
48 opts.merge_base = hash_one(opts.merge_base) | |
49 except CalledProcessError: | |
50 print >> sys.stderr, ( | |
51 'fatal: could not resolve %s as a commit' % (opts.merge_base) | |
52 ) | |
53 return 1 | |
54 | |
55 manual_merge_base(cur, opts.merge_base) | |
56 | |
57 ret = 0 | |
58 actual = get_or_create_merge_base(cur) | |
59 if opts.merge_base and opts.merge_base != actual: | |
60 ret = 1 | |
61 print "Invalid merge_base %s" % opts.merge_base | |
62 | |
63 print "merge_base(%s): %s" % (cur, actual) | |
64 | |
65 return ret | |
66 | |
67 | |
68 if __name__ == '__main__': | |
69 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |