| 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 distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 4074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4085 group.add_option('--pull', action='store_true', dest='pull', | 4085 group.add_option('--pull', action='store_true', dest='pull', |
| 4086 help='Performs a pull before reapplying.') | 4086 help='Performs a pull before reapplying.') |
| 4087 parser.add_option_group(group) | 4087 parser.add_option_group(group) |
| 4088 | 4088 |
| 4089 auth.add_auth_options(parser) | 4089 auth.add_auth_options(parser) |
| 4090 _add_codereview_select_options(parser) | 4090 _add_codereview_select_options(parser) |
| 4091 (options, args) = parser.parse_args(args) | 4091 (options, args) = parser.parse_args(args) |
| 4092 _process_codereview_select_options(parser, options) | 4092 _process_codereview_select_options(parser, options) |
| 4093 auth_config = auth.extract_auth_config_from_options(options) | 4093 auth_config = auth.extract_auth_config_from_options(options) |
| 4094 | 4094 |
| 4095 cl = Changelist(auth_config=auth_config, codereview=options.forced_codereview) | |
| 4096 | 4095 |
| 4097 issue_arg = None | |
| 4098 if options.reapply : | 4096 if options.reapply : |
| 4097 if options.newbranch: |
| 4098 parser.error('--reapply works on the current branch only') |
| 4099 if len(args) > 0: | 4099 if len(args) > 0: |
| 4100 parser.error('--reapply implies no additional arguments.') | 4100 parser.error('--reapply implies no additional arguments') |
| 4101 | 4101 |
| 4102 issue_arg = cl.GetIssue() | 4102 cl = Changelist(auth_config=auth_config, |
| 4103 codereview=options.forced_codereview) |
| 4104 if not cl.GetIssue(): |
| 4105 parser.error('current branch must have an associated issue') |
| 4106 |
| 4103 upstream = cl.GetUpstreamBranch() | 4107 upstream = cl.GetUpstreamBranch() |
| 4104 if upstream == None: | 4108 if upstream == None: |
| 4105 parser.error('No upstream branch specified. Cannot reset branch') | 4109 parser.error('No upstream branch specified. Cannot reset branch') |
| 4106 | 4110 |
| 4107 RunGit(['reset', '--hard', upstream]) | 4111 RunGit(['reset', '--hard', upstream]) |
| 4108 if options.pull: | 4112 if options.pull: |
| 4109 RunGit(['pull']) | 4113 RunGit(['pull']) |
| 4110 else: | |
| 4111 if len(args) != 1: | |
| 4112 parser.error('Must specify issue number or url') | |
| 4113 issue_arg = args[0] | |
| 4114 | 4114 |
| 4115 if not issue_arg: | 4115 return cl.CMDPatchIssue(cl.GetIssue(), options.reject, options.nocommit, |
| 4116 parser.print_help() | 4116 options.directory) |
| 4117 |
| 4118 if len(args) != 1 or not args[0]: |
| 4119 parser.error('Must specify issue number or url') |
| 4120 |
| 4121 # We don't want uncommitted changes mixed up with the patch. |
| 4122 if git_common.is_dirty_git_tree('patch'): |
| 4117 return 1 | 4123 return 1 |
| 4118 | 4124 |
| 4125 if options.newbranch: |
| 4126 if options.force: |
| 4127 RunGit(['branch', '-D', options.newbranch], |
| 4128 stderr=subprocess2.PIPE, error_ok=True) |
| 4129 RunGit(['new-branch', options.newbranch]) |
| 4130 |
| 4131 cl = Changelist(auth_config=auth_config, codereview=options.forced_codereview) |
| 4132 |
| 4119 if cl.IsGerrit(): | 4133 if cl.IsGerrit(): |
| 4120 if options.reject: | 4134 if options.reject: |
| 4121 parser.error('--reject is not supported with Gerrit codereview.') | 4135 parser.error('--reject is not supported with Gerrit codereview.') |
| 4122 if options.nocommit: | 4136 if options.nocommit: |
| 4123 parser.error('--nocommit is not supported with Gerrit codereview.') | 4137 parser.error('--nocommit is not supported with Gerrit codereview.') |
| 4124 if options.directory: | 4138 if options.directory: |
| 4125 parser.error('--directory is not supported with Gerrit codereview.') | 4139 parser.error('--directory is not supported with Gerrit codereview.') |
| 4126 | 4140 |
| 4127 # We don't want uncommitted changes mixed up with the patch. | 4141 return cl.CMDPatchIssue(args[0], options.reject, options.nocommit, |
| 4128 if git_common.is_dirty_git_tree('patch'): | |
| 4129 return 1 | |
| 4130 | |
| 4131 if options.newbranch: | |
| 4132 if options.reapply: | |
| 4133 parser.error("--reapply excludes any option other than --pull") | |
| 4134 if options.force: | |
| 4135 RunGit(['branch', '-D', options.newbranch], | |
| 4136 stderr=subprocess2.PIPE, error_ok=True) | |
| 4137 RunGit(['checkout', '-b', options.newbranch, | |
| 4138 Changelist().GetUpstreamBranch()]) | |
| 4139 | |
| 4140 return cl.CMDPatchIssue(issue_arg, options.reject, options.nocommit, | |
| 4141 options.directory) | 4142 options.directory) |
| 4142 | 4143 |
| 4143 | 4144 |
| 4144 def CMDrebase(parser, args): | 4145 def CMDrebase(parser, args): |
| 4145 """Rebases current branch on top of svn repo.""" | 4146 """Rebases current branch on top of svn repo.""" |
| 4146 # Provide a wrapper for git svn rebase to help avoid accidental | 4147 # Provide a wrapper for git svn rebase to help avoid accidental |
| 4147 # git svn dcommit. | 4148 # git svn dcommit. |
| 4148 # It's the only command that doesn't use parser at all since we just defer | 4149 # It's the only command that doesn't use parser at all since we just defer |
| 4149 # execution to git-svn. | 4150 # execution to git-svn. |
| 4150 | 4151 |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4887 if __name__ == '__main__': | 4888 if __name__ == '__main__': |
| 4888 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4889 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 4889 # unit testing. | 4890 # unit testing. |
| 4890 fix_encoding.fix_encoding() | 4891 fix_encoding.fix_encoding() |
| 4891 setup_color.init() | 4892 setup_color.init() |
| 4892 try: | 4893 try: |
| 4893 sys.exit(main(sys.argv[1:])) | 4894 sys.exit(main(sys.argv[1:])) |
| 4894 except KeyboardInterrupt: | 4895 except KeyboardInterrupt: |
| 4895 sys.stderr.write('interrupted\n') | 4896 sys.stderr.write('interrupted\n') |
| 4896 sys.exit(1) | 4897 sys.exit(1) |
| OLD | NEW |