Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: git_cl.py

Issue 1641903002: Use current issue number for git cl patch (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
2957 CAUTION: This will undo any local changes in this branch""")
2958
2959 group.add_option('--pull', action='store_true', dest='pull',
2960 help="Performs a pull before reapplying.")
2961 parser.add_option_group(group)
2962
2948 auth.add_auth_options(parser) 2963 auth.add_auth_options(parser)
2949 (options, args) = parser.parse_args(args) 2964 (options, args) = parser.parse_args(args)
2950 auth_config = auth.extract_auth_config_from_options(options) 2965 auth_config = auth.extract_auth_config_from_options(options)
2951 2966
2952 if len(args) != 1: 2967 issue_arg = None
2953 parser.print_help() 2968 if options.reapply :
2954 return 1 2969 if len(args) > 0:
2970 parser.error("--reapply implies no additional arguments.")
2955 2971
2956 issue_arg = ParseIssueNum(args[0]) 2972 cl = Changelist()
2973 issue_arg = cl.GetIssue()
2974 upstream = cl.GetUpstreamBranch()
2975 if upstream == None:
2976 parser.error("No upstream branch specified. Cannot reset branch")
2977
2978 RunGit(['reset', '--hard', upstream])
2979 if options.pull:
2980 RunGit(['pull'])
2981 else:
2982 if len(args) != 1:
2983 parser.error("Must specify issue number")
2984
2985 issue_arg = ParseIssueNum(args[0])
2986
2957 # The patch URL works because ParseIssueNum won't do any substitution 2987 # The patch URL works because ParseIssueNum won't do any substitution
2958 # as the re.sub pattern fails to match and just returns it. 2988 # as the re.sub pattern fails to match and just returns it.
2959 if issue_arg == None: 2989 if issue_arg == None:
2960 parser.print_help() 2990 parser.print_help()
2961 return 1 2991 return 1
2962 2992
2963 # We don't want uncommitted changes mixed up with the patch. 2993 # We don't want uncommitted changes mixed up with the patch.
2964 if git_common.is_dirty_git_tree('patch'): 2994 if git_common.is_dirty_git_tree('patch'):
2965 return 1 2995 return 1
2966 2996
2967 # TODO(maruel): Use apply_issue.py 2997 # TODO(maruel): Use apply_issue.py
2968 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? 2998 # TODO(ukai): use gerrit-cherry-pick for gerrit repository?
2969 2999
2970 if options.newbranch: 3000 if options.newbranch:
3001 if options.reapply:
3002 parser.error("--reapply excludes any option other than --pull")
2971 if options.force: 3003 if options.force:
2972 RunGit(['branch', '-D', options.newbranch], 3004 RunGit(['branch', '-D', options.newbranch],
2973 stderr=subprocess2.PIPE, error_ok=True) 3005 stderr=subprocess2.PIPE, error_ok=True)
2974 RunGit(['checkout', '-b', options.newbranch, 3006 RunGit(['checkout', '-b', options.newbranch,
2975 Changelist().GetUpstreamBranch()]) 3007 Changelist().GetUpstreamBranch()])
2976 3008
2977 return PatchIssue(issue_arg, options.reject, options.nocommit, 3009 return PatchIssue(issue_arg, options.reject, options.nocommit,
2978 options.directory, auth_config) 3010 options.directory, auth_config)
2979 3011
2980 3012
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
3715 if __name__ == '__main__': 3747 if __name__ == '__main__':
3716 # These affect sys.stdout so do it outside of main() to simplify mocks in 3748 # These affect sys.stdout so do it outside of main() to simplify mocks in
3717 # unit testing. 3749 # unit testing.
3718 fix_encoding.fix_encoding() 3750 fix_encoding.fix_encoding()
3719 colorama.init() 3751 colorama.init()
3720 try: 3752 try:
3721 sys.exit(main(sys.argv[1:])) 3753 sys.exit(main(sys.argv[1:]))
3722 except KeyboardInterrupt: 3754 except KeyboardInterrupt:
3723 sys.stderr.write('interrupted\n') 3755 sys.stderr.write('interrupted\n')
3724 sys.exit(1) 3756 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698