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 | |
agable
2014/03/25 19:37:23
still no docstring
iannucci
2014/03/26 01:39:49
Done.
| |
6 import argparse | |
7 import sys | |
8 | |
9 import subprocess2 | |
10 | |
11 from git_common import upstream, current_branch, run, tags, set_branch_config | |
12 from git_common import get_or_create_merge_base | |
13 | |
14 import git_rebase_update | |
15 | |
16 def main(args): | |
17 parser = argparse.ArgumentParser() | |
18 parser.add_argument('new_parent') | |
19 opts = parser.parse_args(args) | |
20 | |
21 # TODO(iannucci): Allow specification of the branch-to-reparent | |
22 | |
23 branch = current_branch() | |
24 new_parent = opts.new_parent | |
25 cur_parent = upstream(branch) | |
26 | |
27 if branch == 'HEAD' or not branch: | |
28 parser.error('Must be on the branch you want to reparent') | |
29 if new_parent == cur_parent: | |
30 parser.error('Cannot reparent a branch to its existing parent') | |
31 | |
32 get_or_create_merge_base(branch, cur_parent) | |
33 | |
34 all_tags = tags() | |
35 if cur_parent in all_tags: | |
36 cur_parent += ' [tag]' | |
37 | |
38 try: | |
39 run('show-ref', new_parent) | |
40 except subprocess2.CalledProcessError: | |
41 print >> sys.stderr, 'fatal: invalid reference: %s' % new_parent | |
42 return 1 | |
43 | |
44 if new_parent in all_tags: | |
45 print ("Reparenting %s to track %s [tag] (was %s)" | |
46 % (branch, new_parent, cur_parent)) | |
47 set_branch_config(branch, 'remote', '.') | |
48 set_branch_config(branch, 'merge', new_parent) | |
49 else: | |
50 print ("Reparenting %s to track %s (was %s)" | |
51 % (branch, new_parent, cur_parent)) | |
52 run('branch', '--set-upstream-to', new_parent, branch) | |
53 | |
54 # TODO(iannucci): ONLY rebase-update the branch which moved (and dependants) | |
55 return git_rebase_update.main(['--no_fetch']) | |
agable
2014/03/25 19:37:23
directly calling another script's main() method ma
iannucci
2014/03/26 01:39:49
done as much as I'm going to :p
| |
56 | |
57 | |
58 if __name__ == '__main__': # pragma: no cover | |
59 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |