OLD | NEW |
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 import logging | 10 import logging |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import re | 13 import re |
| 14 import stat |
14 import sys | 15 import sys |
15 import textwrap | 16 import textwrap |
16 import urlparse | 17 import urlparse |
17 import urllib2 | 18 import urllib2 |
18 | 19 |
19 try: | 20 try: |
20 import readline # pylint: disable=F0401,W0611 | 21 import readline # pylint: disable=F0401,W0611 |
21 except ImportError: | 22 except ImportError: |
22 pass | 23 pass |
23 | 24 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 SetProperty('server', 'CODE_REVIEW_SERVER') | 728 SetProperty('server', 'CODE_REVIEW_SERVER') |
728 # Only server setting is required. Other settings can be absent. | 729 # Only server setting is required. Other settings can be absent. |
729 # In that case, we ignore errors raised during option deletion attempt. | 730 # In that case, we ignore errors raised during option deletion attempt. |
730 SetProperty('cc', 'CC_LIST', unset_error_ok=True) | 731 SetProperty('cc', 'CC_LIST', unset_error_ok=True) |
731 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) | 732 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) |
732 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) | 733 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) |
733 | 734 |
734 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: | 735 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: |
735 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) | 736 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) |
736 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) | 737 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) |
737 # Install the standard commit-msg hook. | |
738 RunCommand(['scp', '-p', '-P', keyvals['GERRIT_PORT'], | |
739 '%s:hooks/commit-msg' % keyvals['GERRIT_HOST'], | |
740 os.path.join(settings.GetRoot(), | |
741 '.git', 'hooks', 'commit-msg')]) | |
742 | 738 |
743 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 739 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
744 #should be of the form | 740 #should be of the form |
745 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 741 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
746 #ORIGIN_URL_CONFIG: http://src.chromium.org/git | 742 #ORIGIN_URL_CONFIG: http://src.chromium.org/git |
747 RunGit(['config', keyvals['PUSH_URL_CONFIG'], | 743 RunGit(['config', keyvals['PUSH_URL_CONFIG'], |
748 keyvals['ORIGIN_URL_CONFIG']]) | 744 keyvals['ORIGIN_URL_CONFIG']]) |
749 | 745 |
750 | 746 |
| 747 def DownloadHooks(): |
| 748 """downloads hooks""" |
| 749 if settings.GetIsGerrit(): |
| 750 server_url = settings.GetDefaultServerUrl() |
| 751 src = '%s/tools/hooks/commit-msg' % server_url |
| 752 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') |
| 753 fileobj = urllib2.urlopen(src) |
| 754 commit_msg = open(dst, 'w') |
| 755 commit_msg.write(fileobj.read()) |
| 756 fileobj.close() |
| 757 commit_msg.close() |
| 758 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) |
| 759 |
| 760 |
751 @usage('[repo root containing codereview.settings]') | 761 @usage('[repo root containing codereview.settings]') |
752 def CMDconfig(parser, args): | 762 def CMDconfig(parser, args): |
753 """edit configuration for this tree""" | 763 """edit configuration for this tree""" |
754 | 764 |
755 _, args = parser.parse_args(args) | 765 _, args = parser.parse_args(args) |
756 if len(args) == 0: | 766 if len(args) == 0: |
757 GetCodereviewSettingsInteractively() | 767 GetCodereviewSettingsInteractively() |
| 768 DownloadHooks() |
758 return 0 | 769 return 0 |
759 | 770 |
760 url = args[0] | 771 url = args[0] |
761 if not url.endswith('codereview.settings'): | 772 if not url.endswith('codereview.settings'): |
762 url = os.path.join(url, 'codereview.settings') | 773 url = os.path.join(url, 'codereview.settings') |
763 | 774 |
764 # Load code review settings and download hooks (if available). | 775 # Load code review settings and download hooks (if available). |
765 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) | 776 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) |
| 777 DownloadHooks() |
766 return 0 | 778 return 0 |
767 | 779 |
768 | 780 |
769 def CMDstatus(parser, args): | 781 def CMDstatus(parser, args): |
770 """show status of changelists""" | 782 """show status of changelists""" |
771 parser.add_option('--field', | 783 parser.add_option('--field', |
772 help='print only specific field (desc|id|patch|url)') | 784 help='print only specific field (desc|id|patch|url)') |
773 (options, args) = parser.parse_args(args) | 785 (options, args) = parser.parse_args(args) |
774 | 786 |
775 # TODO: maybe make show_branches a flag if necessary. | 787 # TODO: maybe make show_branches a flag if necessary. |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1510 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1499 | 1511 |
1500 # Not a known command. Default to help. | 1512 # Not a known command. Default to help. |
1501 GenUsage(parser, 'help') | 1513 GenUsage(parser, 'help') |
1502 return CMDhelp(parser, argv) | 1514 return CMDhelp(parser, argv) |
1503 | 1515 |
1504 | 1516 |
1505 if __name__ == '__main__': | 1517 if __name__ == '__main__': |
1506 fix_encoding.fix_encoding() | 1518 fix_encoding.fix_encoding() |
1507 sys.exit(main(sys.argv[1:])) | 1519 sys.exit(main(sys.argv[1:])) |
OLD | NEW |