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 |
11 import subprocess2 | 11 import subprocess2 |
12 | 12 |
13 from git_common import upstream, current_branch, run, tags, set_branch_config | 13 from git_common import upstream, current_branch, run, tags, set_branch_config |
14 from git_common import get_or_create_merge_base, root | 14 from git_common import get_or_create_merge_base, root, manual_merge_base |
15 | 15 |
16 import git_rebase_update | 16 import git_rebase_update |
17 | 17 |
18 def main(args): | 18 def main(args): |
19 root_ref = root() | 19 root_ref = root() |
20 | 20 |
21 parser = argparse.ArgumentParser() | 21 parser = argparse.ArgumentParser() |
22 g = parser.add_mutually_exclusive_group() | 22 g = parser.add_mutually_exclusive_group() |
23 g.add_argument('new_parent', nargs='?', | 23 g.add_argument('new_parent', nargs='?', |
24 help='New parent branch (or tag) to reparent to.') | 24 help='New parent branch (or tag) to reparent to.') |
(...skipping 12 matching lines...) Expand all Loading... | |
37 new_parent = 'lkgr' | 37 new_parent = 'lkgr' |
38 else: | 38 else: |
39 new_parent = opts.new_parent | 39 new_parent = opts.new_parent |
40 cur_parent = upstream(branch) | 40 cur_parent = upstream(branch) |
41 | 41 |
42 if branch == 'HEAD' or not branch: | 42 if branch == 'HEAD' or not branch: |
43 parser.error('Must be on the branch you want to reparent') | 43 parser.error('Must be on the branch you want to reparent') |
44 if new_parent == cur_parent: | 44 if new_parent == cur_parent: |
45 parser.error('Cannot reparent a branch to its existing parent') | 45 parser.error('Cannot reparent a branch to its existing parent') |
46 | 46 |
47 get_or_create_merge_base(branch, cur_parent) | 47 mbase = get_or_create_merge_base(branch, cur_parent) |
48 | 48 |
49 all_tags = tags() | 49 all_tags = tags() |
50 if cur_parent in all_tags: | 50 if cur_parent in all_tags: |
51 cur_parent += ' [tag]' | 51 cur_parent += ' [tag]' |
52 | 52 |
53 try: | 53 try: |
54 run('show-ref', new_parent) | 54 run('show-ref', new_parent) |
55 except subprocess2.CalledProcessError: | 55 except subprocess2.CalledProcessError: |
56 print >> sys.stderr, 'fatal: invalid reference: %s' % new_parent | 56 print >> sys.stderr, 'fatal: invalid reference: %s' % new_parent |
57 return 1 | 57 return 1 |
58 | 58 |
59 if new_parent in all_tags: | 59 if new_parent in all_tags: |
60 print ("Reparenting %s to track %s [tag] (was %s)" | 60 print ("Reparenting %s to track %s [tag] (was %s)" |
61 % (branch, new_parent, cur_parent)) | 61 % (branch, new_parent, cur_parent)) |
62 set_branch_config(branch, 'remote', '.') | 62 set_branch_config(branch, 'remote', '.') |
63 set_branch_config(branch, 'merge', new_parent) | 63 set_branch_config(branch, 'merge', new_parent) |
64 else: | 64 else: |
65 print ("Reparenting %s to track %s (was %s)" | 65 print ("Reparenting %s to track %s (was %s)" |
66 % (branch, new_parent, cur_parent)) | 66 % (branch, new_parent, cur_parent)) |
67 run('branch', '--set-upstream-to', new_parent, branch) | 67 run('branch', '--set-upstream-to', new_parent, branch) |
68 | 68 |
69 manual_merge_base(branch, mbase, new_parent) | |
iannucci
2014/05/15 22:20:17
this sets the same base for the branch given the n
| |
70 | |
69 # TODO(iannucci): ONLY rebase-update the branch which moved (and dependants) | 71 # TODO(iannucci): ONLY rebase-update the branch which moved (and dependants) |
70 return git_rebase_update.main(['--no_fetch']) | 72 return git_rebase_update.main(['--no_fetch']) |
71 | 73 |
72 | 74 |
73 if __name__ == '__main__': # pragma: no cover | 75 if __name__ == '__main__': # pragma: no cover |
74 sys.exit(main(sys.argv[1:])) | 76 sys.exit(main(sys.argv[1:])) |
OLD | NEW |