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 subprocess | 10 import subprocess |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 os.remove(filename) | 661 os.remove(filename) |
662 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) | 662 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) |
663 return stripcomment_re.sub('', text).strip() | 663 return stripcomment_re.sub('', text).strip() |
664 | 664 |
665 | 665 |
666 def RunHook(hook, upstream_branch, error_ok=False): | 666 def RunHook(hook, upstream_branch, error_ok=False): |
667 """Run a given hook if it exists. By default, we fail on errors.""" | 667 """Run a given hook if it exists. By default, we fail on errors.""" |
668 hook = '%s/%s' % (settings.GetRoot(), hook) | 668 hook = '%s/%s' % (settings.GetRoot(), hook) |
669 if not os.path.exists(hook): | 669 if not os.path.exists(hook): |
670 return | 670 return |
671 return RunCommand([hook, upstream_branch], error_ok=error_ok, | 671 # msysgit requires sys.executable to be present. This assumes all hooks are |
ncarter (slow)
2011/01/29 02:19:05
Sorry if my email wasn't totally clear: the entire
| |
672 redirect_stdout=False) | 672 # scripted in python. Which should be okay. |
673 cmd = [hook, upstream_branch] | |
674 if sys.platform == 'win32': | |
675 with open(hook, 'r') as f: | |
676 if f.readline().startswith('#!/usr/bin/python'): | |
677 cmd.insert(0, sys.executable) | |
678 else: | |
679 DieWithError('It seems your environment is msysgit, and the hook [%s] ' | |
680 'will not execute correctly. The hook must be scripted ' | |
681 'in Python for this to work.') | |
682 return RunCommand(cmd, error_ok=error_ok, redirect_stdout=False) | |
673 | 683 |
674 | 684 |
675 def CMDpresubmit(parser, args): | 685 def CMDpresubmit(parser, args): |
676 """run presubmit tests on the current changelist""" | 686 """run presubmit tests on the current changelist""" |
677 parser.add_option('--upload', action='store_true', | 687 parser.add_option('--upload', action='store_true', |
678 help='Run upload hook instead of the push/dcommit hook') | 688 help='Run upload hook instead of the push/dcommit hook') |
679 (options, args) = parser.parse_args(args) | 689 (options, args) = parser.parse_args(args) |
680 | 690 |
681 # Make sure index is up-to-date before running diff-index. | 691 # Make sure index is up-to-date before running diff-index. |
682 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 692 RunGit(['update-index', '--refresh', '-q'], error_ok=True) |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1267 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1277 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1268 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1278 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1269 | 1279 |
1270 # Not a known command. Default to help. | 1280 # Not a known command. Default to help. |
1271 GenUsage(parser, 'help') | 1281 GenUsage(parser, 'help') |
1272 return CMDhelp(parser, argv) | 1282 return CMDhelp(parser, argv) |
1273 | 1283 |
1274 | 1284 |
1275 if __name__ == '__main__': | 1285 if __name__ == '__main__': |
1276 sys.exit(main(sys.argv[1:])) | 1286 sys.exit(main(sys.argv[1:])) |
OLD | NEW |