| 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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
| 9 | 9 |
| 10 from __future__ import print_function | 10 from __future__ import print_function |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 'last-upload-hash', | 1315 'last-upload-hash', |
| 1316 self._codereview_impl.IssueConfigKey(), | 1316 self._codereview_impl.IssueConfigKey(), |
| 1317 self._codereview_impl.PatchsetConfigKey(), | 1317 self._codereview_impl.PatchsetConfigKey(), |
| 1318 self._codereview_impl.CodereviewServerConfigKey(), | 1318 self._codereview_impl.CodereviewServerConfigKey(), |
| 1319 ] + self._PostUnsetIssueProperties() | 1319 ] + self._PostUnsetIssueProperties() |
| 1320 for prop in reset_suffixes: | 1320 for prop in reset_suffixes: |
| 1321 self._GitSetBranchConfigValue(prop, None, error_ok=True) | 1321 self._GitSetBranchConfigValue(prop, None, error_ok=True) |
| 1322 self.issue = None | 1322 self.issue = None |
| 1323 self.patchset = None | 1323 self.patchset = None |
| 1324 | 1324 |
| 1325 def GetChange(self, upstream_branch, author): | 1325 def GetChange(self, upstream_branch, author, local_description=False): |
| 1326 if not self.GitSanityChecks(upstream_branch): | 1326 if not self.GitSanityChecks(upstream_branch): |
| 1327 DieWithError('\nGit sanity check failure') | 1327 DieWithError('\nGit sanity check failure') |
| 1328 | 1328 |
| 1329 root = settings.GetRelativeRoot() | 1329 root = settings.GetRelativeRoot() |
| 1330 if not root: | 1330 if not root: |
| 1331 root = '.' | 1331 root = '.' |
| 1332 absroot = os.path.abspath(root) | 1332 absroot = os.path.abspath(root) |
| 1333 | 1333 |
| 1334 # We use the sha1 of HEAD as a name of this change. | 1334 # We use the sha1 of HEAD as a name of this change. |
| 1335 name = RunGitWithCode(['rev-parse', 'HEAD'])[1].strip() | 1335 name = RunGitWithCode(['rev-parse', 'HEAD'])[1].strip() |
| 1336 # Need to pass a relative path for msysgit. | 1336 # Need to pass a relative path for msysgit. |
| 1337 try: | 1337 try: |
| 1338 files = scm.GIT.CaptureStatus([root], '.', upstream_branch) | 1338 files = scm.GIT.CaptureStatus([root], '.', upstream_branch) |
| 1339 except subprocess2.CalledProcessError: | 1339 except subprocess2.CalledProcessError: |
| 1340 DieWithError( | 1340 DieWithError( |
| 1341 ('\nFailed to diff against upstream branch %s\n\n' | 1341 ('\nFailed to diff against upstream branch %s\n\n' |
| 1342 'This branch probably doesn\'t exist anymore. To reset the\n' | 1342 'This branch probably doesn\'t exist anymore. To reset the\n' |
| 1343 'tracking branch, please run\n' | 1343 'tracking branch, please run\n' |
| 1344 ' git branch --set-upstream %s trunk\n' | 1344 ' git branch --set-upstream %s trunk\n' |
| 1345 'replacing trunk with origin/master or the relevant branch') % | 1345 'replacing trunk with origin/master or the relevant branch') % |
| 1346 (upstream_branch, self.GetBranch())) | 1346 (upstream_branch, self.GetBranch())) |
| 1347 | 1347 |
| 1348 issue = self.GetIssue() | 1348 issue = self.GetIssue() |
| 1349 patchset = self.GetPatchset() | 1349 patchset = self.GetPatchset() |
| 1350 if issue: | 1350 if issue and not local_description: |
| 1351 description = self.GetDescription() | 1351 description = self.GetDescription() |
| 1352 else: | 1352 else: |
| 1353 # If the change was never uploaded, use the log messages of all commits | 1353 # If the change was never uploaded, use the log messages of all commits |
| 1354 # up to the branch point, as git cl upload will prefill the description | 1354 # up to the branch point, as git cl upload will prefill the description |
| 1355 # with these log messages. | 1355 # with these log messages. |
| 1356 args = ['log', '--pretty=format:%s%n%n%b', '%s...' % (upstream_branch)] | 1356 args = ['log', '--pretty=format:%s%n%n%b', '%s...' % (upstream_branch)] |
| 1357 description = RunGitWithCode(args)[1].strip() | 1357 description = RunGitWithCode(args)[1].strip() |
| 1358 | 1358 |
| 1359 if not author: | 1359 if not author: |
| 1360 author = RunGit(['config', 'user.email']).strip() or None | 1360 author = RunGit(['config', 'user.email']).strip() or None |
| (...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3574 json.dump(summary, f) | 3574 json.dump(summary, f) |
| 3575 return 0 | 3575 return 0 |
| 3576 | 3576 |
| 3577 | 3577 |
| 3578 @subcommand.usage('[codereview url or issue id]') | 3578 @subcommand.usage('[codereview url or issue id]') |
| 3579 def CMDdescription(parser, args): | 3579 def CMDdescription(parser, args): |
| 3580 """Brings up the editor for the current CL's description.""" | 3580 """Brings up the editor for the current CL's description.""" |
| 3581 parser.add_option('-d', '--display', action='store_true', | 3581 parser.add_option('-d', '--display', action='store_true', |
| 3582 help='Display the description instead of opening an editor') | 3582 help='Display the description instead of opening an editor') |
| 3583 parser.add_option('-n', '--new-description', | 3583 parser.add_option('-n', '--new-description', |
| 3584 help='New description to set for this issue (- for stdin)') | 3584 help='New description to set for this issue (- for stdin, ' |
| 3585 '+ to load from local commit HEAD)') |
| 3585 | 3586 |
| 3586 _add_codereview_select_options(parser) | 3587 _add_codereview_select_options(parser) |
| 3587 auth.add_auth_options(parser) | 3588 auth.add_auth_options(parser) |
| 3588 options, args = parser.parse_args(args) | 3589 options, args = parser.parse_args(args) |
| 3589 _process_codereview_select_options(parser, options) | 3590 _process_codereview_select_options(parser, options) |
| 3590 | 3591 |
| 3591 target_issue = None | 3592 target_issue = None |
| 3592 if len(args) > 0: | 3593 if len(args) > 0: |
| 3593 target_issue = ParseIssueNumberArgument(args[0]) | 3594 target_issue = ParseIssueNumberArgument(args[0]) |
| 3594 if not target_issue.valid: | 3595 if not target_issue.valid: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3613 description = ChangeDescription(cl.GetDescription()) | 3614 description = ChangeDescription(cl.GetDescription()) |
| 3614 | 3615 |
| 3615 if options.display: | 3616 if options.display: |
| 3616 print(description.description) | 3617 print(description.description) |
| 3617 return 0 | 3618 return 0 |
| 3618 | 3619 |
| 3619 if options.new_description: | 3620 if options.new_description: |
| 3620 text = options.new_description | 3621 text = options.new_description |
| 3621 if text == '-': | 3622 if text == '-': |
| 3622 text = '\n'.join(l.rstrip() for l in sys.stdin) | 3623 text = '\n'.join(l.rstrip() for l in sys.stdin) |
| 3624 elif text == '+': |
| 3625 base_branch = cl.GetCommonAncestorWithUpstream() |
| 3626 change = cl.GetChange(base_branch, None, local_description=True) |
| 3627 text = change.FullDescriptionText() |
| 3623 | 3628 |
| 3624 description.set_description(text) | 3629 description.set_description(text) |
| 3625 else: | 3630 else: |
| 3626 description.prompt() | 3631 description.prompt() |
| 3627 | 3632 |
| 3628 if cl.GetDescription() != description.description: | 3633 if cl.GetDescription() != description.description: |
| 3629 cl.UpdateDescription(description.description) | 3634 cl.UpdateDescription(description.description) |
| 3630 return 0 | 3635 return 0 |
| 3631 | 3636 |
| 3632 | 3637 |
| (...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5217 if __name__ == '__main__': | 5222 if __name__ == '__main__': |
| 5218 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5223 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 5219 # unit testing. | 5224 # unit testing. |
| 5220 fix_encoding.fix_encoding() | 5225 fix_encoding.fix_encoding() |
| 5221 setup_color.init() | 5226 setup_color.init() |
| 5222 try: | 5227 try: |
| 5223 sys.exit(main(sys.argv[1:])) | 5228 sys.exit(main(sys.argv[1:])) |
| 5224 except KeyboardInterrupt: | 5229 except KeyboardInterrupt: |
| 5225 sys.stderr.write('interrupted\n') | 5230 sys.stderr.write('interrupted\n') |
| 5226 sys.exit(1) | 5231 sys.exit(1) |
| OLD | NEW |