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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2938 parser.add_option('-f', '--force', action='store_true', | 2938 parser.add_option('-f', '--force', action='store_true', |
2939 help='with -b, clobber any existing branch') | 2939 help='with -b, clobber any existing branch') |
2940 parser.add_option('-d', '--directory', action='store', metavar='DIR', | 2940 parser.add_option('-d', '--directory', action='store', metavar='DIR', |
2941 help='Change to the directory DIR immediately, ' | 2941 help='Change to the directory DIR immediately, ' |
2942 'before doing anything else.') | 2942 'before doing anything else.') |
2943 parser.add_option('--reject', action='store_true', | 2943 parser.add_option('--reject', action='store_true', |
2944 help='failed patches spew .rej files rather than ' | 2944 help='failed patches spew .rej files rather than ' |
2945 'attempting a 3-way merge') | 2945 'attempting a 3-way merge') |
2946 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 2946 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
2947 help="don't commit after patch applies") | 2947 help="don't commit after patch applies") |
2948 | |
2949 group = optparse.OptionGroup(parser, | |
2950 """Options for continuing work on the current issue uploaded | |
2951 from a different clone (e.g. different machine). Must be used independently from | |
2952 the other options. No issue number should be specified, and the branch must have | |
2953 an issue number associated with it""") | |
2954 group.add_option('--reapply', action='store_true', | |
2955 dest='reapply', | |
2956 help="Reset the branch and reapply the issue.") | |
iannucci
2016/01/30 02:54:20
I would add some warning text here: "CAUTION: This
Mircea Trofin
2016/02/02 00:35:49
Done.
| |
2957 group.add_option('--pull', action='store_true', dest='pull', | |
2958 help="Performs a pull before reapplying.") | |
2959 parser.add_option_group(group) | |
2960 | |
2948 auth.add_auth_options(parser) | 2961 auth.add_auth_options(parser) |
2949 (options, args) = parser.parse_args(args) | 2962 (options, args) = parser.parse_args(args) |
2950 auth_config = auth.extract_auth_config_from_options(options) | 2963 auth_config = auth.extract_auth_config_from_options(options) |
2951 | 2964 |
2952 if len(args) != 1: | 2965 issue_arg = None |
2953 parser.print_help() | 2966 if options.reapply : |
2954 return 1 | 2967 if len(args) > 0: |
2968 parser.print_help() | |
iannucci
2016/01/30 02:54:20
maybe want to try
parser.error("--reapply implies
Dirk Pranke
2016/02/01 23:19:19
nit: s/if len(args) > 0:/if args:/
Mircea Trofin
2016/02/02 00:35:49
Done.
Mircea Trofin
2016/02/02 00:35:49
I saw len(args) elsewhere. For consistency, I'd pr
| |
2969 return 1 | |
2955 | 2970 |
2956 issue_arg = ParseIssueNum(args[0]) | 2971 cl = Changelist() |
2972 issue_arg = cl.GetIssue() | |
2973 upstream = cl.GetUpstreamBranch() | |
2974 RunGit(['reset', '--hard', upstream]) | |
iannucci
2016/01/30 02:54:21
you may need to check for None here. Some folks (s
Mircea Trofin
2016/02/02 00:35:49
Actually, that'll set the branch to master, but I
| |
2975 if options.pull: | |
2976 RunGit(['pull']) | |
2977 else: | |
2978 if len(args) != 1: | |
2979 parser.print_help() | |
2980 return 1 | |
iannucci
2016/01/30 02:54:21
same here and below re: parser.error
Mircea Trofin
2016/02/02 00:35:49
Done.
| |
2981 issue_arg = ParseIssueNum(args[0]) | |
2982 | |
2957 # The patch URL works because ParseIssueNum won't do any substitution | 2983 # The patch URL works because ParseIssueNum won't do any substitution |
2958 # as the re.sub pattern fails to match and just returns it. | 2984 # as the re.sub pattern fails to match and just returns it. |
2959 if issue_arg == None: | 2985 if issue_arg == None: |
2960 parser.print_help() | 2986 parser.print_help() |
2961 return 1 | 2987 return 1 |
2962 | 2988 |
2963 # We don't want uncommitted changes mixed up with the patch. | 2989 # We don't want uncommitted changes mixed up with the patch. |
2964 if git_common.is_dirty_git_tree('patch'): | 2990 if git_common.is_dirty_git_tree('patch'): |
2965 return 1 | 2991 return 1 |
2966 | 2992 |
2967 # TODO(maruel): Use apply_issue.py | 2993 # TODO(maruel): Use apply_issue.py |
2968 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 2994 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
2969 | 2995 |
2970 if options.newbranch: | 2996 if options.newbranch: |
2997 if options.reapply: | |
2998 parser.print_help() | |
2999 return 1 | |
2971 if options.force: | 3000 if options.force: |
2972 RunGit(['branch', '-D', options.newbranch], | 3001 RunGit(['branch', '-D', options.newbranch], |
2973 stderr=subprocess2.PIPE, error_ok=True) | 3002 stderr=subprocess2.PIPE, error_ok=True) |
2974 RunGit(['checkout', '-b', options.newbranch, | 3003 RunGit(['checkout', '-b', options.newbranch, |
2975 Changelist().GetUpstreamBranch()]) | 3004 Changelist().GetUpstreamBranch()]) |
2976 | 3005 |
2977 return PatchIssue(issue_arg, options.reject, options.nocommit, | 3006 return PatchIssue(issue_arg, options.reject, options.nocommit, |
2978 options.directory, auth_config) | 3007 options.directory, auth_config) |
2979 | 3008 |
2980 | 3009 |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3715 if __name__ == '__main__': | 3744 if __name__ == '__main__': |
3716 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3745 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3717 # unit testing. | 3746 # unit testing. |
3718 fix_encoding.fix_encoding() | 3747 fix_encoding.fix_encoding() |
3719 colorama.init() | 3748 colorama.init() |
3720 try: | 3749 try: |
3721 sys.exit(main(sys.argv[1:])) | 3750 sys.exit(main(sys.argv[1:])) |
3722 except KeyboardInterrupt: | 3751 except KeyboardInterrupt: |
3723 sys.stderr.write('interrupted\n') | 3752 sys.stderr.write('interrupted\n') |
3724 sys.exit(1) | 3753 sys.exit(1) |
OLD | NEW |