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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 734 |
735 | 735 |
736 def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt): | 736 def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt): |
737 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | 737 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
738 import presubmit_support | 738 import presubmit_support |
739 import scm | 739 import scm |
740 import watchlists | 740 import watchlists |
741 | 741 |
742 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() | 742 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() |
743 if not root: | 743 if not root: |
744 root = "." | 744 root = '.' |
745 absroot = os.path.abspath(root) | 745 absroot = os.path.abspath(root) |
746 if not root: | 746 if not root: |
747 raise Exception("Could not get root directory.") | 747 raise Exception('Could not get root directory.') |
748 | 748 |
749 # We use the sha1 of HEAD as a name of this change. | 749 # We use the sha1 of HEAD as a name of this change. |
750 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() | 750 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() |
751 files = scm.GIT.CaptureStatus([root], upstream_branch) | 751 files = scm.GIT.CaptureStatus([root], upstream_branch) |
752 | 752 |
753 cl = Changelist() | 753 cl = Changelist() |
754 issue = ConvertToInteger(cl.GetIssue()) | 754 issue = ConvertToInteger(cl.GetIssue()) |
755 patchset = ConvertToInteger(cl.GetPatchset()) | 755 patchset = ConvertToInteger(cl.GetPatchset()) |
756 if issue: | 756 if issue: |
757 description = cl.GetDescription() | 757 description = cl.GetDescription() |
758 else: | 758 else: |
759 # If the change was never uploaded, use the log messages of all commits | 759 # If the change was never uploaded, use the log messages of all commits |
760 # up to the branch point, as git cl upload will prefill the description | 760 # up to the branch point, as git cl upload will prefill the description |
761 # with these log messages. | 761 # with these log messages. |
762 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', | 762 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', |
763 '%s...' % (upstream_branch)]).strip() | 763 '%s...' % (upstream_branch)]).strip() |
764 change = presubmit_support.GitChange(name, description, absroot, files, | 764 change = presubmit_support.GitChange(name, description, absroot, files, |
765 issue, patchset) | 765 issue, patchset) |
766 | 766 |
767 # Apply watchlists on upload. | 767 # Apply watchlists on upload. |
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 should_continue = presubmit_support.DoPresubmitChecks(change, committing, | 776 should_continue = 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=False, 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 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1408 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1409 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1409 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1410 | 1410 |
1411 # Not a known command. Default to help. | 1411 # Not a known command. Default to help. |
1412 GenUsage(parser, 'help') | 1412 GenUsage(parser, 'help') |
1413 return CMDhelp(parser, argv) | 1413 return CMDhelp(parser, argv) |
1414 | 1414 |
1415 | 1415 |
1416 if __name__ == '__main__': | 1416 if __name__ == '__main__': |
1417 sys.exit(main(sys.argv[1:])) | 1417 sys.exit(main(sys.argv[1:])) |
OLD | NEW |