| 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 """Change the upstream of the current branch.""" | 6 """Change the upstream of the current branch.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 help='New parent branch (or tag) to reparent to.') | 24 help='New parent branch (or tag) to reparent to.') |
| 25 g.add_argument('--root', action='store_true', | 25 g.add_argument('--root', action='store_true', |
| 26 help='Reparent to the configured root branch (%s).' % root_ref) | 26 help='Reparent to the configured root branch (%s).' % root_ref) |
| 27 g.add_argument('--lkgr', action='store_true', | 27 g.add_argument('--lkgr', action='store_true', |
| 28 help='Reparent to the lkgr tag.') | 28 help='Reparent to the lkgr tag.') |
| 29 opts = parser.parse_args(args) | 29 opts = parser.parse_args(args) |
| 30 | 30 |
| 31 # TODO(iannucci): Allow specification of the branch-to-reparent | 31 # TODO(iannucci): Allow specification of the branch-to-reparent |
| 32 | 32 |
| 33 branch = current_branch() | 33 branch = current_branch() |
| 34 |
| 34 if opts.root: | 35 if opts.root: |
| 35 new_parent = root_ref | 36 new_parent = root_ref |
| 36 elif opts.lkgr: | 37 elif opts.lkgr: |
| 37 new_parent = 'lkgr' | 38 new_parent = 'lkgr' |
| 38 else: | 39 else: |
| 39 if not opts.new_parent: | 40 if not opts.new_parent: |
| 40 parser.error('Must specify new parent somehow') | 41 parser.error('Must specify new parent somehow') |
| 41 new_parent = opts.new_parent | 42 new_parent = opts.new_parent |
| 42 cur_parent = upstream(branch) | 43 cur_parent = upstream(branch) |
| 43 | 44 |
| 44 if branch == 'HEAD' or not branch: | 45 if branch == 'HEAD' or not branch: |
| 45 parser.error('Must be on the branch you want to reparent') | 46 parser.error('Must be on the branch you want to reparent') |
| 46 if new_parent == cur_parent: | 47 if new_parent == cur_parent: |
| 47 parser.error('Cannot reparent a branch to its existing parent') | 48 parser.error('Cannot reparent a branch to its existing parent') |
| 48 | 49 |
| 50 if not cur_parent: |
| 51 msg = ( |
| 52 "Unable to determine %s@{upstream}.\n\nThis can happen if you didn't use " |
| 53 "`git new-branch` to create the branch and haven't used " |
| 54 "`git branch --set-upstream-to` to assign it one.\n\nPlease assign an " |
| 55 "upstream branch and then run this command again." |
| 56 ) |
| 57 print >> sys.stderr, msg % branch |
| 58 return 1 |
| 59 |
| 49 mbase = get_or_create_merge_base(branch, cur_parent) | 60 mbase = get_or_create_merge_base(branch, cur_parent) |
| 50 | 61 |
| 51 all_tags = tags() | 62 all_tags = tags() |
| 52 if cur_parent in all_tags: | 63 if cur_parent in all_tags: |
| 53 cur_parent += ' [tag]' | 64 cur_parent += ' [tag]' |
| 54 | 65 |
| 55 try: | 66 try: |
| 56 run('show-ref', new_parent) | 67 run('show-ref', new_parent) |
| 57 except subprocess2.CalledProcessError: | 68 except subprocess2.CalledProcessError: |
| 58 print >> sys.stderr, 'fatal: invalid reference: %s' % new_parent | 69 print >> sys.stderr, 'fatal: invalid reference: %s' % new_parent |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 # TODO(iannucci): ONLY rebase-update the branch which moved (and dependants) | 84 # TODO(iannucci): ONLY rebase-update the branch which moved (and dependants) |
| 74 return git_rebase_update.main(['--no-fetch']) | 85 return git_rebase_update.main(['--no-fetch']) |
| 75 | 86 |
| 76 | 87 |
| 77 if __name__ == '__main__': # pragma: no cover | 88 if __name__ == '__main__': # pragma: no cover |
| 78 try: | 89 try: |
| 79 sys.exit(main(sys.argv[1:])) | 90 sys.exit(main(sys.argv[1:])) |
| 80 except KeyboardInterrupt: | 91 except KeyboardInterrupt: |
| 81 sys.stderr.write('interrupted\n') | 92 sys.stderr.write('interrupted\n') |
| 82 sys.exit(1) | 93 sys.exit(1) |
| OLD | NEW |