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

Side by Side Diff: git_reparent_branch.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
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:]))
OLDNEW
« git_rename_branch.py ('K') | « git_rename_branch.py ('k') | git_squash_branch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698