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

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: one more argparse 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/21 01:14:21 docstring
6 import sys
7 import re
8
9 from git_common import current_branch, branches, run
10
11 def main(argv):
12 # TODO(iannucci): Use argparse
agable 2014/03/21 01:14:21 Do this now
13 assert 2 <= len(argv) < 3, "Must supply (<newname>) or (<oldname> <newname>)"
14 if len(argv) == 2:
15 old_name = current_branch()
16 new_name = argv[1]
17 else:
18 old_name = argv[1]
19 new_name = argv[2]
20 assert old_name in branches(), "<oldname> must exist"
21 assert new_name not in branches(), "<newname> must not exist"
22
23 run('branch', '-m', old_name, new_name)
24
25 matcher = re.compile(r'^branch\.(.*)\.merge$')
26 branches_to_fix = []
27 for line in run('config', '-l').splitlines():
28 key, value = line.split('=', 1)
agable 2014/03/21 01:14:21 does this properly strip? Lots of gitconfigs have
29 if value == 'refs/heads/' + old_name:
30 m = matcher.match(key)
31 if m:
32 branch = m.group(1)
33 remote = run('config', '--get', 'branch.%s.remote' % branch)
34 if remote == '.':
agable 2014/03/21 01:14:21 Please comment on what the special value '.' means
iannucci 2014/03/22 04:17:35 Er... why here? This is defined by git-config...
35 branches_to_fix.append(branch)
36 for b in branches_to_fix:
37 run('config', 'branch.%s.merge' % b, 'refs/heads/' + new_name)
38
39
40 if __name__ == '__main__':
41 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698