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