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

Side by Side Diff: git_rename_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: 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 (c) 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 import sys
6 import re
7
8 from git_common import current_branch, branches, run
9
10 def main(argv):
11 # TODO(iannucci): Use argparse
agable 2014/02/28 20:14:16 Do this now.
Ryan Tseng 2014/02/28 21:22:05 How is this different than just "git branch -m"?
12 assert 2 <= len(argv) < 3, "Must supply (<newname>) or (<oldname> <newname>)"
13 if len(argv) == 2:
14 old_name = current_branch()
15 new_name = argv[1]
16 else:
17 old_name = argv[1]
18 new_name = argv[2]
19 assert old_name in branches(), "<oldname> must exist"
agable 2014/02/28 20:14:16 Since it shells out, only make one call to branche
Ryan Tseng 2014/02/28 21:22:05 "Error: Branch \"%s\" does not exist" % old_name
20 assert new_name not in branches(), "<newname> must not exist"
Ryan Tseng 2014/02/28 21:22:05 "Error: A branch named \"%s\" already exists" % ne
21
22 run('branch', '-m', old_name, new_name)
23
24 matcher = re.compile(r'^branch\.(.*)\.merge$')
25 branches_to_fix = []
26 for line in run('config', '-l').splitlines():
27 key, value = line.split('=', 1)
28 if value == 'refs/heads/' + old_name:
29 m = matcher.match(key)
30 if m:
31 branch = m.group(1)
32 remote = run('config', '--get', 'branch.%s.remote' % branch)
33 if remote == '.':
34 branches_to_fix.append(branch)
35 for b in branches_to_fix:
36 run('config', 'branch.%s.merge' % b, 'refs/heads/' + new_name)
37
38
39 if __name__ == '__main__':
40 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698