| 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 |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | 543 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
| 544 change = self.GetChange(upstream_branch, author) | 544 change = self.GetChange(upstream_branch, author) |
| 545 | 545 |
| 546 # Apply watchlists on upload. | 546 # Apply watchlists on upload. |
| 547 if not committing: | 547 if not committing: |
| 548 watchlist = watchlists.Watchlists(change.RepositoryRoot()) | 548 watchlist = watchlists.Watchlists(change.RepositoryRoot()) |
| 549 files = [f.LocalPath() for f in change.AffectedFiles()] | 549 files = [f.LocalPath() for f in change.AffectedFiles()] |
| 550 self.SetWatchers(watchlist.GetWatchersForPaths(files)) | 550 self.SetWatchers(watchlist.GetWatchersForPaths(files)) |
| 551 | 551 |
| 552 try: | 552 try: |
| 553 output = presubmit_support.DoPresubmitChecks(change, committing, | 553 return presubmit_support.DoPresubmitChecks(change, committing, |
| 554 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 554 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
| 555 default_presubmit=None, may_prompt=may_prompt, | 555 default_presubmit=None, may_prompt=may_prompt, |
| 556 rietveld_obj=self.RpcServer()) | 556 rietveld_obj=self.RpcServer()) |
| 557 except presubmit_support.PresubmitFailure, e: | 557 except presubmit_support.PresubmitFailure, e: |
| 558 DieWithError( | 558 DieWithError( |
| 559 ('%s\nMaybe your depot_tools is out of date?\n' | 559 ('%s\nMaybe your depot_tools is out of date?\n' |
| 560 'If all fails, contact maruel@') % e) | 560 'If all fails, contact maruel@') % e) |
| 561 | 561 |
| 562 # TODO(dpranke): We should propagate the error out instead of calling | |
| 563 # exit(). | |
| 564 if not output.should_continue(): | |
| 565 sys.exit(1) | |
| 566 | |
| 567 return output | |
| 568 | |
| 569 def CloseIssue(self): | 562 def CloseIssue(self): |
| 570 """Updates the description and closes the issue.""" | 563 """Updates the description and closes the issue.""" |
| 571 issue = int(self.GetIssue()) | 564 issue = int(self.GetIssue()) |
| 572 self.RpcServer().update_description(issue, self.description) | 565 self.RpcServer().update_description(issue, self.description) |
| 573 return self.RpcServer().close_issue(issue) | 566 return self.RpcServer().close_issue(issue) |
| 574 | 567 |
| 575 def SetFlag(self, flag, value): | 568 def SetFlag(self, flag, value): |
| 576 """Patchset must match.""" | 569 """Patchset must match.""" |
| 577 if not self.GetPatchset(): | 570 if not self.GetPatchset(): |
| 578 DieWithError('The patchset needs to match. Send another patchset.') | 571 DieWithError('The patchset needs to match. Send another patchset.') |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 return 1 | 895 return 1 |
| 903 | 896 |
| 904 cl = Changelist() | 897 cl = Changelist() |
| 905 if args: | 898 if args: |
| 906 base_branch = args[0] | 899 base_branch = args[0] |
| 907 else: | 900 else: |
| 908 # Default to diffing against the "upstream" branch. | 901 # Default to diffing against the "upstream" branch. |
| 909 base_branch = cl.GetUpstreamBranch() | 902 base_branch = cl.GetUpstreamBranch() |
| 910 args = [base_branch + "..."] | 903 args = [base_branch + "..."] |
| 911 | 904 |
| 912 if not options.bypass_hooks and not options.force: | 905 if not options.bypass_hooks: |
| 913 hook_results = cl.RunHook(committing=False, upstream_branch=base_branch, | 906 hook_results = cl.RunHook(committing=False, upstream_branch=base_branch, |
| 914 may_prompt=True, | 907 may_prompt=not options.force, |
| 915 verbose=options.verbose, | 908 verbose=options.verbose, |
| 916 author=None) | 909 author=None) |
| 910 if not hook_results.should_continue(): |
| 911 return 1 |
| 917 if not options.reviewers and hook_results.reviewers: | 912 if not options.reviewers and hook_results.reviewers: |
| 918 options.reviewers = hook_results.reviewers | 913 options.reviewers = hook_results.reviewers |
| 919 | 914 |
| 920 | |
| 921 # --no-ext-diff is broken in some versions of Git, so try to work around | 915 # --no-ext-diff is broken in some versions of Git, so try to work around |
| 922 # this by overriding the environment (but there is still a problem if the | 916 # this by overriding the environment (but there is still a problem if the |
| 923 # git config key "diff.external" is used). | 917 # git config key "diff.external" is used). |
| 924 env = os.environ.copy() | 918 env = os.environ.copy() |
| 925 if 'GIT_EXTERNAL_DIFF' in env: | 919 if 'GIT_EXTERNAL_DIFF' in env: |
| 926 del env['GIT_EXTERNAL_DIFF'] | 920 del env['GIT_EXTERNAL_DIFF'] |
| 927 subprocess2.call( | 921 subprocess2.call( |
| 928 ['git', 'diff', '--no-ext-diff', '--stat', '-M'] + args, env=env) | 922 ['git', 'diff', '--no-ext-diff', '--stat', '-M'] + args, env=env) |
| 929 | 923 |
| 930 upload_args = ['--assume_yes'] # Don't ask about untracked files. | 924 upload_args = ['--assume_yes'] # Don't ask about untracked files. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 svn_head = RunGit(['log', '--grep=^git-svn-id:', '-1', | 1055 svn_head = RunGit(['log', '--grep=^git-svn-id:', '-1', |
| 1062 '--pretty=format:%H']) | 1056 '--pretty=format:%H']) |
| 1063 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch]) | 1057 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch]) |
| 1064 if extra_commits: | 1058 if extra_commits: |
| 1065 print ('This branch has %d additional commits not upstreamed yet.' | 1059 print ('This branch has %d additional commits not upstreamed yet.' |
| 1066 % len(extra_commits.splitlines())) | 1060 % len(extra_commits.splitlines())) |
| 1067 print ('Upstream "%s" or rebase this branch on top of the upstream trunk ' | 1061 print ('Upstream "%s" or rebase this branch on top of the upstream trunk ' |
| 1068 'before attempting to %s.' % (base_branch, cmd)) | 1062 'before attempting to %s.' % (base_branch, cmd)) |
| 1069 return 1 | 1063 return 1 |
| 1070 | 1064 |
| 1071 if not options.bypass_hooks and not options.force: | 1065 if not options.bypass_hooks: |
| 1072 author = None | 1066 author = None |
| 1073 if options.contributor: | 1067 if options.contributor: |
| 1074 author = re.search(r'\<(.*)\>', options.contributor).group(1) | 1068 author = re.search(r'\<(.*)\>', options.contributor).group(1) |
| 1075 cl.RunHook(committing=True, upstream_branch=base_branch, | 1069 hook_results = cl.RunHook( |
| 1076 may_prompt=True, verbose=options.verbose, | 1070 committing=True, |
| 1077 author=author) | 1071 upstream_branch=base_branch, |
| 1072 may_prompt=not options.force, |
| 1073 verbose=options.verbose, |
| 1074 author=author) |
| 1075 if not hook_results.should_continue(): |
| 1076 return 1 |
| 1078 | 1077 |
| 1079 if cmd == 'dcommit': | 1078 if cmd == 'dcommit': |
| 1080 # Check the tree status if the tree status URL is set. | 1079 # Check the tree status if the tree status URL is set. |
| 1081 status = GetTreeStatus() | 1080 status = GetTreeStatus() |
| 1082 if 'closed' == status: | 1081 if 'closed' == status: |
| 1083 print ('The tree is closed. Please wait for it to reopen. Use ' | 1082 print('The tree is closed. Please wait for it to reopen. Use ' |
| 1084 '"git cl dcommit -f" to commit on a closed tree.') | 1083 '"git cl dcommit --bypass-hooks" to commit on a closed tree.') |
| 1085 return 1 | 1084 return 1 |
| 1086 elif 'unknown' == status: | 1085 elif 'unknown' == status: |
| 1087 print ('Unable to determine tree status. Please verify manually and ' | 1086 print('Unable to determine tree status. Please verify manually and ' |
| 1088 'use "git cl dcommit -f" to commit on a closed tree.') | 1087 'use "git cl dcommit --bypass-hooks" to commit on a closed tree.') |
| 1089 else: | 1088 else: |
| 1090 breakpad.SendStack( | 1089 breakpad.SendStack( |
| 1091 'GitClHooksBypassedCommit', | 1090 'GitClHooksBypassedCommit', |
| 1092 'Issue %s/%s bypassed hook when committing' % | 1091 'Issue %s/%s bypassed hook when committing' % |
| 1093 (cl.GetRietveldServer(), cl.GetIssue()), | 1092 (cl.GetRietveldServer(), cl.GetIssue()), |
| 1094 verbose=False) | 1093 verbose=False) |
| 1095 | 1094 |
| 1096 description = options.message | 1095 description = options.message |
| 1097 if not description and cl.GetIssue(): | 1096 if not description and cl.GetIssue(): |
| 1098 description = cl.GetDescription() | 1097 description = cl.GetDescription() |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1428 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1430 | 1429 |
| 1431 # Not a known command. Default to help. | 1430 # Not a known command. Default to help. |
| 1432 GenUsage(parser, 'help') | 1431 GenUsage(parser, 'help') |
| 1433 return CMDhelp(parser, argv) | 1432 return CMDhelp(parser, argv) |
| 1434 | 1433 |
| 1435 | 1434 |
| 1436 if __name__ == '__main__': | 1435 if __name__ == '__main__': |
| 1437 fix_encoding.fix_encoding() | 1436 fix_encoding.fix_encoding() |
| 1438 sys.exit(main(sys.argv[1:])) | 1437 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |