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

Side by Side Diff: git_cl.py

Issue 1799553003: Stop installing Gerrit commit-msg hooks in git cl config. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: fix todo Created 4 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
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 return 'branch.%s.rietveldpatchset' % self.GetBranch() 1326 return 'branch.%s.rietveldpatchset' % self.GetBranch()
1327 1327
1328 def _RietveldServer(self): 1328 def _RietveldServer(self):
1329 """Returns the git setting that stores this change's rietveld server.""" 1329 """Returns the git setting that stores this change's rietveld server."""
1330 branch = self.GetBranch() 1330 branch = self.GetBranch()
1331 if branch: 1331 if branch:
1332 return 'branch.%s.rietveldserver' % branch 1332 return 'branch.%s.rietveldserver' % branch
1333 return None 1333 return None
1334 1334
1335 1335
1336 def GetCodereviewSettingsInteractively():
1337 """Prompt the user for settings."""
1338 # TODO(ukai): ask code review system is rietveld or gerrit?
1339 server = settings.GetDefaultServerUrl(error_ok=True)
1340 prompt = 'Rietveld server (host[:port])'
1341 prompt += ' [%s]' % (server or DEFAULT_SERVER)
1342 newserver = ask_for_data(prompt + ':')
1343 if not server and not newserver:
1344 newserver = DEFAULT_SERVER
1345 if newserver:
1346 newserver = gclient_utils.UpgradeToHttps(newserver)
1347 if newserver != server:
1348 RunGit(['config', 'rietveld.server', newserver])
1349
1350 def SetProperty(initial, caption, name, is_url):
1351 prompt = caption
1352 if initial:
1353 prompt += ' ("x" to clear) [%s]' % initial
1354 new_val = ask_for_data(prompt + ':')
1355 if new_val == 'x':
1356 RunGit(['config', '--unset-all', 'rietveld.' + name], error_ok=True)
1357 elif new_val:
1358 if is_url:
1359 new_val = gclient_utils.UpgradeToHttps(new_val)
1360 if new_val != initial:
1361 RunGit(['config', 'rietveld.' + name, new_val])
1362
1363 SetProperty(settings.GetDefaultCCList(), 'CC list', 'cc', False)
1364 SetProperty(settings.GetDefaultPrivateFlag(),
1365 'Private flag (rietveld only)', 'private', False)
1366 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL',
1367 'tree-status-url', False)
1368 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True)
1369 SetProperty(settings.GetBugPrefix(), 'Bug Prefix', 'bug-prefix', False)
1370 SetProperty(settings.GetRunPostUploadHook(), 'Run Post Upload Hook',
1371 'run-post-upload-hook', False)
1372
1373 # TODO: configure a default branch to diff against, rather than this
1374 # svn-based hackery.
1375
1376
1377 class ChangeDescription(object): 1336 class ChangeDescription(object):
1378 """Contains a parsed form of the change description.""" 1337 """Contains a parsed form of the change description."""
1379 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$' 1338 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$'
1380 BUG_LINE = r'^[ \t]*(BUG)[ \t]*=[ \t]*(.*?)[ \t]*$' 1339 BUG_LINE = r'^[ \t]*(BUG)[ \t]*=[ \t]*(.*?)[ \t]*$'
1381 1340
1382 def __init__(self, description): 1341 def __init__(self, description):
1383 self._description_lines = (description or '').strip().splitlines() 1342 self._description_lines = (description or '').strip().splitlines()
1384 1343
1385 @property # www.logilab.org/ticket/89786 1344 @property # www.logilab.org/ticket/89786
1386 def description(self): # pylint: disable=E0202 1345 def description(self): # pylint: disable=E0202
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 os.remove(dst) 1572 os.remove(dst)
1614 DieWithError('\nFailed to download hooks.\n' 1573 DieWithError('\nFailed to download hooks.\n'
1615 'You need to download from\n%s\n' 1574 'You need to download from\n%s\n'
1616 'into .git/hooks/commit-msg and ' 1575 'into .git/hooks/commit-msg and '
1617 'chmod +x .git/hooks/commit-msg' % src) 1576 'chmod +x .git/hooks/commit-msg' % src)
1618 1577
1619 # TODO(tandrii): remove this once repos which call this method directly are 1578 # TODO(tandrii): remove this once repos which call this method directly are
1620 # upgraded. See http://crbug.com/579176. 1579 # upgraded. See http://crbug.com/579176.
1621 DownloadHooks = DownloadGerritHook 1580 DownloadHooks = DownloadGerritHook
1622 1581
1582
1583 def GetRietveldCodereviewSettingsInteractively():
1584 """Prompt the user for settings."""
1585 server = settings.GetDefaultServerUrl(error_ok=True)
1586 prompt = 'Rietveld server (host[:port])'
1587 prompt += ' [%s]' % (server or DEFAULT_SERVER)
1588 newserver = ask_for_data(prompt + ':')
1589 if not server and not newserver:
1590 newserver = DEFAULT_SERVER
1591 if newserver:
1592 newserver = gclient_utils.UpgradeToHttps(newserver)
1593 if newserver != server:
1594 RunGit(['config', 'rietveld.server', newserver])
1595
1596 def SetProperty(initial, caption, name, is_url):
1597 prompt = caption
1598 if initial:
1599 prompt += ' ("x" to clear) [%s]' % initial
1600 new_val = ask_for_data(prompt + ':')
1601 if new_val == 'x':
1602 RunGit(['config', '--unset-all', 'rietveld.' + name], error_ok=True)
1603 elif new_val:
1604 if is_url:
1605 new_val = gclient_utils.UpgradeToHttps(new_val)
1606 if new_val != initial:
1607 RunGit(['config', 'rietveld.' + name, new_val])
1608
1609 SetProperty(settings.GetDefaultCCList(), 'CC list', 'cc', False)
1610 SetProperty(settings.GetDefaultPrivateFlag(),
1611 'Private flag (rietveld only)', 'private', False)
1612 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL',
1613 'tree-status-url', False)
1614 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True)
1615 SetProperty(settings.GetBugPrefix(), 'Bug Prefix', 'bug-prefix', False)
1616 SetProperty(settings.GetRunPostUploadHook(), 'Run Post Upload Hook',
1617 'run-post-upload-hook', False)
1618
1623 @subcommand.usage('[repo root containing codereview.settings]') 1619 @subcommand.usage('[repo root containing codereview.settings]')
1624 def CMDconfig(parser, args): 1620 def CMDconfig(parser, args):
1625 """Edits configuration for this tree.""" 1621 """Edits configuration for this tree."""
1626 1622
1623 print('WARNING: git cl config works for Rietveld only.\n'
1624 'For Gerrit, see http://crbug.com/579160.')
1625 # TODO(tandrii): add Gerrit support as part of http://crbug.com/579160.
1627 parser.add_option('--activate-update', action='store_true', 1626 parser.add_option('--activate-update', action='store_true',
1628 help='activate auto-updating [rietveld] section in ' 1627 help='activate auto-updating [rietveld] section in '
1629 '.git/config') 1628 '.git/config')
1630 parser.add_option('--deactivate-update', action='store_true', 1629 parser.add_option('--deactivate-update', action='store_true',
1631 help='deactivate auto-updating [rietveld] section in ' 1630 help='deactivate auto-updating [rietveld] section in '
1632 '.git/config') 1631 '.git/config')
1633 options, args = parser.parse_args(args) 1632 options, args = parser.parse_args(args)
1634 1633
1635 if options.deactivate_update: 1634 if options.deactivate_update:
1636 RunGit(['config', 'rietveld.autoupdate', 'false']) 1635 RunGit(['config', 'rietveld.autoupdate', 'false'])
1637 return 1636 return
1638 1637
1639 if options.activate_update: 1638 if options.activate_update:
1640 RunGit(['config', '--unset', 'rietveld.autoupdate']) 1639 RunGit(['config', '--unset', 'rietveld.autoupdate'])
1641 return 1640 return
1642 1641
1643 if len(args) == 0: 1642 if len(args) == 0:
1644 GetCodereviewSettingsInteractively() 1643 GetRietveldCodereviewSettingsInteractively()
1645 DownloadGerritHook(True)
1646 return 0 1644 return 0
1647 1645
1648 url = args[0] 1646 url = args[0]
1649 if not url.endswith('codereview.settings'): 1647 if not url.endswith('codereview.settings'):
1650 url = os.path.join(url, 'codereview.settings') 1648 url = os.path.join(url, 'codereview.settings')
1651 1649
1652 # Load code review settings and download hooks (if available). 1650 # Load code review settings and download hooks (if available).
1653 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) 1651 LoadCodereviewSettingsFromFile(urllib2.urlopen(url))
1654 DownloadGerritHook(True)
1655 return 0 1652 return 0
1656 1653
1657 1654
1658 def CMDbaseurl(parser, args): 1655 def CMDbaseurl(parser, args):
1659 """Gets or sets base-url for this branch.""" 1656 """Gets or sets base-url for this branch."""
1660 branchref = RunGit(['symbolic-ref', 'HEAD']).strip() 1657 branchref = RunGit(['symbolic-ref', 'HEAD']).strip()
1661 branch = ShortBranchName(branchref) 1658 branch = ShortBranchName(branchref)
1662 _, args = parser.parse_args(args) 1659 _, args = parser.parse_args(args)
1663 if not args: 1660 if not args:
1664 print("Current base-url:") 1661 print("Current base-url:")
(...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after
3983 if __name__ == '__main__': 3980 if __name__ == '__main__':
3984 # These affect sys.stdout so do it outside of main() to simplify mocks in 3981 # These affect sys.stdout so do it outside of main() to simplify mocks in
3985 # unit testing. 3982 # unit testing.
3986 fix_encoding.fix_encoding() 3983 fix_encoding.fix_encoding()
3987 colorama.init() 3984 colorama.init()
3988 try: 3985 try:
3989 sys.exit(main(sys.argv[1:])) 3986 sys.exit(main(sys.argv[1:]))
3990 except KeyboardInterrupt: 3987 except KeyboardInterrupt:
3991 sys.stderr.write('interrupted\n') 3988 sys.stderr.write('interrupted\n')
3992 sys.exit(1) 3989 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698