OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 """Set this branch's issue. If issue=0, clears the issue.""" | 481 """Set this branch's issue. If issue=0, clears the issue.""" |
482 if issue: | 482 if issue: |
483 RunGit(['config', self._IssueSetting(), str(issue)]) | 483 RunGit(['config', self._IssueSetting(), str(issue)]) |
484 if self.rietveld_server: | 484 if self.rietveld_server: |
485 RunGit(['config', self._RietveldServer(), self.rietveld_server]) | 485 RunGit(['config', self._RietveldServer(), self.rietveld_server]) |
486 else: | 486 else: |
487 RunGit(['config', '--unset', self._IssueSetting()]) | 487 RunGit(['config', '--unset', self._IssueSetting()]) |
488 self.SetPatchset(0) | 488 self.SetPatchset(0) |
489 self.has_issue = False | 489 self.has_issue = False |
490 | 490 |
491 def RunHook(self, committing, upstream_branch, may_prompt, verbose, author): | 491 def GetChange(self, upstream_branch, author): |
492 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | |
493 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' | 492 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' |
494 absroot = os.path.abspath(root) | 493 absroot = os.path.abspath(root) |
495 | 494 |
496 # We use the sha1 of HEAD as a name of this change. | 495 # We use the sha1 of HEAD as a name of this change. |
497 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() | 496 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() |
498 # Need to pass a relative path for msysgit. | 497 # Need to pass a relative path for msysgit. |
499 files = scm.GIT.CaptureStatus([root], upstream_branch) | 498 files = scm.GIT.CaptureStatus([root], upstream_branch) |
500 | 499 |
501 issue = ConvertToInteger(self.GetIssue()) | 500 issue = ConvertToInteger(self.GetIssue()) |
502 patchset = ConvertToInteger(self.GetPatchset()) | 501 patchset = ConvertToInteger(self.GetPatchset()) |
503 if issue: | 502 if issue: |
504 description = self.GetDescription() | 503 description = self.GetDescription() |
505 else: | 504 else: |
506 # If the change was never uploaded, use the log messages of all commits | 505 # If the change was never uploaded, use the log messages of all commits |
507 # up to the branch point, as git cl upload will prefill the description | 506 # up to the branch point, as git cl upload will prefill the description |
508 # with these log messages. | 507 # with these log messages. |
509 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', | 508 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', |
510 '%s...' % (upstream_branch)]).strip() | 509 '%s...' % (upstream_branch)]).strip() |
511 | 510 |
512 if not author: | 511 if not author: |
513 author = RunGit(['config', 'user.email']).strip() or None | 512 author = RunGit(['config', 'user.email']).strip() or None |
514 change = presubmit_support.GitChange( | 513 return presubmit_support.GitChange( |
515 name, | 514 name, |
516 description, | 515 description, |
517 absroot, | 516 absroot, |
518 files, | 517 files, |
519 issue, | 518 issue, |
520 patchset, | 519 patchset, |
521 author) | 520 author) |
522 | 521 |
| 522 def RunHook(self, committing, upstream_branch, may_prompt, verbose, author): |
| 523 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
| 524 change = self.GetChange(upstream_branch, author) |
| 525 |
523 # Apply watchlists on upload. | 526 # Apply watchlists on upload. |
524 if not committing: | 527 if not committing: |
525 watchlist = watchlists.Watchlists(change.RepositoryRoot()) | 528 watchlist = watchlists.Watchlists(change.RepositoryRoot()) |
526 files = [f.LocalPath() for f in change.AffectedFiles()] | 529 files = [f.LocalPath() for f in change.AffectedFiles()] |
527 self.SetWatchers(watchlist.GetWatchersForPaths(files)) | 530 self.SetWatchers(watchlist.GetWatchersForPaths(files)) |
528 | 531 |
529 try: | 532 try: |
530 output = presubmit_support.DoPresubmitChecks(change, committing, | 533 output = presubmit_support.DoPresubmitChecks(change, committing, |
531 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 534 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
532 default_presubmit=None, may_prompt=may_prompt, | 535 default_presubmit=None, may_prompt=may_prompt, |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1432 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1430 | 1433 |
1431 # Not a known command. Default to help. | 1434 # Not a known command. Default to help. |
1432 GenUsage(parser, 'help') | 1435 GenUsage(parser, 'help') |
1433 return CMDhelp(parser, argv) | 1436 return CMDhelp(parser, argv) |
1434 | 1437 |
1435 | 1438 |
1436 if __name__ == '__main__': | 1439 if __name__ == '__main__': |
1437 fix_encoding.fix_encoding() | 1440 fix_encoding.fix_encoding() |
1438 sys.exit(main(sys.argv[1:])) | 1441 sys.exit(main(sys.argv[1:])) |
OLD | NEW |