Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: git_mark_merge_base.py

Issue 184253003: Add git-reup and friends (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@freeze_thaw
Patch Set: minor fixes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698