OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import errno | 5 import errno |
6 import logging | 6 import logging |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import re | 9 import re |
10 import StringIO | 10 import StringIO |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 try: | 713 try: |
714 subprocess.check_call(['env', editor, filename]) | 714 subprocess.check_call(['env', editor, filename]) |
715 fileobj = open(filename) | 715 fileobj = open(filename) |
716 result = fileobj.read() | 716 result = fileobj.read() |
717 fileobj.close() | 717 fileobj.close() |
718 finally: | 718 finally: |
719 os.remove(filename) | 719 os.remove(filename) |
720 | 720 |
721 if not result: | 721 if not result: |
722 return | 722 return |
723 | 723 |
724 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) | 724 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) |
725 return stripcomment_re.sub('', result).strip() | 725 return stripcomment_re.sub('', result).strip() |
726 | 726 |
727 | 727 |
728 def ConvertToInteger(inputval): | 728 def ConvertToInteger(inputval): |
729 """Convert a string to integer, but returns either an int or None.""" | 729 """Convert a string to integer, but returns either an int or None.""" |
730 try: | 730 try: |
731 return int(inputval) | 731 return int(inputval) |
732 except (TypeError, ValueError): | 732 except (TypeError, ValueError): |
733 return None | 733 return None |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 if not committing: | 768 if not committing: |
769 watchlist = watchlists.Watchlists(change.RepositoryRoot()) | 769 watchlist = watchlists.Watchlists(change.RepositoryRoot()) |
770 files = [f.LocalPath() for f in change.AffectedFiles()] | 770 files = [f.LocalPath() for f in change.AffectedFiles()] |
771 watchers = watchlist.GetWatchersForPaths(files) | 771 watchers = watchlist.GetWatchersForPaths(files) |
772 RunCommand(['git', 'config', '--replace-all', | 772 RunCommand(['git', 'config', '--replace-all', |
773 'rietveld.extracc', ','.join(watchers)]) | 773 'rietveld.extracc', ','.join(watchers)]) |
774 | 774 |
775 output = StringIO.StringIO() | 775 output = StringIO.StringIO() |
776 res = presubmit_support.DoPresubmitChecks(change, committing, | 776 res = presubmit_support.DoPresubmitChecks(change, committing, |
777 verbose=None, output_stream=output, input_stream=sys.stdin, | 777 verbose=None, output_stream=output, input_stream=sys.stdin, |
778 default_presubmit=None, may_prompt=may_prompt, tbr=tbr, | 778 default_presubmit=None, may_prompt=False, tbr=tbr, |
779 host_url=cl.GetRietveldServer()) | 779 host_url=cl.GetRietveldServer()) |
780 hook_results = HookResults(output.getvalue()) | 780 hook_results = HookResults(output.getvalue()) |
781 if hook_results.output: | 781 if hook_results.output: |
782 print hook_results.output | 782 print hook_results.output |
783 | 783 |
784 # TODO(dpranke): We should propagate the error out instead of calling exit(). | 784 # TODO(dpranke): We should propagate the error out instead of calling exit(). |
785 if not res: | 785 if not res and ('** Presubmit ERRORS **' in hook_results.output or |
M-A Ruel
2011/03/12 15:37:31
with '\n' ?
Dirk Pranke
2011/03/12 22:47:47
I don't understand this comment?
M-A Ruel
2011/03/13 00:53:00
I meant to use '** Presubmit ERRORS **\n' so that
| |
786 sys.exit(1) | 786 '** Presubmit WARNINGS **' in hook_results.output): |
787 res = True | |
788 | |
789 if res: | |
790 if may_prompt: | |
791 response = raw_input('Are you sure you want to continue? (y/N): ') | |
792 if not response.lower().startswith('y'): | |
793 sys.exit(1) | |
794 else: | |
795 sys.exit(1) | |
796 | |
M-A Ruel
2011/03/12 15:37:31
remove one extra line.
| |
797 | |
787 return hook_results | 798 return hook_results |
788 | 799 |
789 | 800 |
790 def CMDpresubmit(parser, args): | 801 def CMDpresubmit(parser, args): |
791 """run presubmit tests on the current changelist""" | 802 """run presubmit tests on the current changelist""" |
792 parser.add_option('--upload', action='store_true', | 803 parser.add_option('--upload', action='store_true', |
793 help='Run upload hook instead of the push/dcommit hook') | 804 help='Run upload hook instead of the push/dcommit hook') |
794 (options, args) = parser.parse_args(args) | 805 (options, args) = parser.parse_args(args) |
795 | 806 |
796 # Make sure index is up-to-date before running diff-index. | 807 # Make sure index is up-to-date before running diff-index. |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1396 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1407 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1397 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1408 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1398 | 1409 |
1399 # Not a known command. Default to help. | 1410 # Not a known command. Default to help. |
1400 GenUsage(parser, 'help') | 1411 GenUsage(parser, 'help') |
1401 return CMDhelp(parser, argv) | 1412 return CMDhelp(parser, argv) |
1402 | 1413 |
1403 | 1414 |
1404 if __name__ == '__main__': | 1415 if __name__ == '__main__': |
1405 sys.exit(main(sys.argv[1:])) | 1416 sys.exit(main(sys.argv[1:])) |
OLD | NEW |