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

Side by Side Diff: git_cl.py

Issue 1764453002: Gerrit: announce deprecation of auto-download of commit-msg hook. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@G075
Patch Set: rebase 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 | no next file » | 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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 # The only value that actually changes the behavior is 595 # The only value that actually changes the behavior is
596 # autoupdate = "false". Everything else means "true". 596 # autoupdate = "false". Everything else means "true".
597 autoupdate = RunGit(['config', 'rietveld.autoupdate'], 597 autoupdate = RunGit(['config', 'rietveld.autoupdate'],
598 error_ok=True 598 error_ok=True
599 ).strip().lower() 599 ).strip().lower()
600 600
601 cr_settings_file = FindCodereviewSettingsFile() 601 cr_settings_file = FindCodereviewSettingsFile()
602 if autoupdate != 'false' and cr_settings_file: 602 if autoupdate != 'false' and cr_settings_file:
603 LoadCodereviewSettingsFromFile(cr_settings_file) 603 LoadCodereviewSettingsFromFile(cr_settings_file)
604 # set updated to True to avoid infinite calling loop 604 # set updated to True to avoid infinite calling loop
605 # through DownloadHooks 605 # through DownloadGerritHook
606 self.updated = True 606 self.updated = True
607 DownloadHooks(False) 607 DownloadGerritHook(False)
608 self.updated = True 608 self.updated = True
609 609
610 def GetDefaultServerUrl(self, error_ok=False): 610 def GetDefaultServerUrl(self, error_ok=False):
611 if not self.default_server: 611 if not self.default_server:
612 self.LazyUpdateIfNeeded() 612 self.LazyUpdateIfNeeded()
613 self.default_server = gclient_utils.UpgradeToHttps( 613 self.default_server = gclient_utils.UpgradeToHttps(
614 self._GetRietveldConfig('server', error_ok=True)) 614 self._GetRietveldConfig('server', error_ok=True))
615 if error_ok: 615 if error_ok:
616 return self.default_server 616 return self.default_server
617 if not self.default_server: 617 if not self.default_server:
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 with open(destination, 'w') as f: 1563 with open(destination, 'w') as f:
1564 f.write(urllib2.urlopen(source).read()) 1564 f.write(urllib2.urlopen(source).read())
1565 1565
1566 1566
1567 def hasSheBang(fname): 1567 def hasSheBang(fname):
1568 """Checks fname is a #! script.""" 1568 """Checks fname is a #! script."""
1569 with open(fname) as f: 1569 with open(fname) as f:
1570 return f.read(2).startswith('#!') 1570 return f.read(2).startswith('#!')
1571 1571
1572 1572
1573 def DownloadHooks(force): 1573 def DownloadGerritHook(force):
1574 """downloads hooks 1574 """Download and install Gerrit commit-msg hook.
1575 1575
1576 Args: 1576 Args:
1577 force: True to update hooks. False to install hooks if not present. 1577 force: True to update hooks. False to install hooks if not present.
1578 """ 1578 """
1579 if not settings.GetIsGerrit(): 1579 if not settings.GetIsGerrit():
1580 return 1580 return
1581 src = 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg' 1581 src = 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg'
1582 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') 1582 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg')
1583 if not os.access(dst, os.X_OK): 1583 if not os.access(dst, os.X_OK):
1584 if os.path.exists(dst): 1584 if os.path.exists(dst):
1585 if not force: 1585 if not force:
1586 return 1586 return
1587 try: 1587 try:
1588 print(
1589 'WARNING: installing Gerrit commit-msg hook.\n'
1590 ' This behavior of git cl will soon be disabled.\n'
1591 ' See bug http://crbug.com/579176.')
1588 urlretrieve(src, dst) 1592 urlretrieve(src, dst)
1589 if not hasSheBang(dst): 1593 if not hasSheBang(dst):
1590 DieWithError('Not a script: %s\n' 1594 DieWithError('Not a script: %s\n'
1591 'You need to download from\n%s\n' 1595 'You need to download from\n%s\n'
1592 'into .git/hooks/commit-msg and ' 1596 'into .git/hooks/commit-msg and '
1593 'chmod +x .git/hooks/commit-msg' % (dst, src)) 1597 'chmod +x .git/hooks/commit-msg' % (dst, src))
1594 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) 1598 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
1595 except Exception: 1599 except Exception:
1596 if os.path.exists(dst): 1600 if os.path.exists(dst):
1597 os.remove(dst) 1601 os.remove(dst)
(...skipping 18 matching lines...) Expand all
1616 if options.deactivate_update: 1620 if options.deactivate_update:
1617 RunGit(['config', 'rietveld.autoupdate', 'false']) 1621 RunGit(['config', 'rietveld.autoupdate', 'false'])
1618 return 1622 return
1619 1623
1620 if options.activate_update: 1624 if options.activate_update:
1621 RunGit(['config', '--unset', 'rietveld.autoupdate']) 1625 RunGit(['config', '--unset', 'rietveld.autoupdate'])
1622 return 1626 return
1623 1627
1624 if len(args) == 0: 1628 if len(args) == 0:
1625 GetCodereviewSettingsInteractively() 1629 GetCodereviewSettingsInteractively()
1626 DownloadHooks(True) 1630 DownloadGerritHook(True)
1627 return 0 1631 return 0
1628 1632
1629 url = args[0] 1633 url = args[0]
1630 if not url.endswith('codereview.settings'): 1634 if not url.endswith('codereview.settings'):
1631 url = os.path.join(url, 'codereview.settings') 1635 url = os.path.join(url, 'codereview.settings')
1632 1636
1633 # Load code review settings and download hooks (if available). 1637 # Load code review settings and download hooks (if available).
1634 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) 1638 LoadCodereviewSettingsFromFile(urllib2.urlopen(url))
1635 DownloadHooks(True) 1639 DownloadGerritHook(True)
1636 return 0 1640 return 0
1637 1641
1638 1642
1639 def CMDbaseurl(parser, args): 1643 def CMDbaseurl(parser, args):
1640 """Gets or sets base-url for this branch.""" 1644 """Gets or sets base-url for this branch."""
1641 branchref = RunGit(['symbolic-ref', 'HEAD']).strip() 1645 branchref = RunGit(['symbolic-ref', 'HEAD']).strip()
1642 branch = ShortBranchName(branchref) 1646 branch = ShortBranchName(branchref)
1643 _, args = parser.parse_args(args) 1647 _, args = parser.parse_args(args)
1644 if not args: 1648 if not args:
1645 print("Current base-url:") 1649 print("Current base-url:")
(...skipping 2335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3981 if __name__ == '__main__': 3985 if __name__ == '__main__':
3982 # These affect sys.stdout so do it outside of main() to simplify mocks in 3986 # These affect sys.stdout so do it outside of main() to simplify mocks in
3983 # unit testing. 3987 # unit testing.
3984 fix_encoding.fix_encoding() 3988 fix_encoding.fix_encoding()
3985 colorama.init() 3989 colorama.init()
3986 try: 3990 try:
3987 sys.exit(main(sys.argv[1:])) 3991 sys.exit(main(sys.argv[1:]))
3988 except KeyboardInterrupt: 3992 except KeyboardInterrupt:
3989 sys.stderr.write('interrupted\n') 3993 sys.stderr.write('interrupted\n')
3990 sys.exit(1) 3994 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698