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 3247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3258 print(' %s : %s' % (dependent_branch, upload_status)) | 3258 print(' %s : %s' % (dependent_branch, upload_status)) |
3259 print() | 3259 print() |
3260 | 3260 |
3261 return 0 | 3261 return 0 |
3262 | 3262 |
3263 | 3263 |
3264 def CMDarchive(parser, args): | 3264 def CMDarchive(parser, args): |
3265 """Archives and deletes branches associated with closed changelists.""" | 3265 """Archives and deletes branches associated with closed changelists.""" |
3266 parser.add_option( | 3266 parser.add_option( |
3267 '-j', '--maxjobs', action='store', type=int, | 3267 '-j', '--maxjobs', action='store', type=int, |
3268 help='The maximum number of jobs to use when retrieving review status') | 3268 help='The maximum number of jobs to use when retrieving review status.') |
3269 parser.add_option( | 3269 parser.add_option( |
3270 '-f', '--force', action='store_true', | 3270 '-f', '--force', action='store_true', |
3271 help='Bypasses the confirmation prompt.') | 3271 help='Bypasses the confirmation prompt.') |
| 3272 parser.add_option( |
| 3273 '-d', '--dry-run', action='store_true', |
| 3274 help='Skip the branch tagging and removal steps.') |
| 3275 parser.add_option( |
| 3276 '-t', '--notags', action='store_true', |
| 3277 help='Do not tag archived branches. ' |
| 3278 'Note: local commit history may be lost.') |
3272 | 3279 |
3273 auth.add_auth_options(parser) | 3280 auth.add_auth_options(parser) |
3274 options, args = parser.parse_args(args) | 3281 options, args = parser.parse_args(args) |
3275 if args: | 3282 if args: |
3276 parser.error('Unsupported args: %s' % ' '.join(args)) | 3283 parser.error('Unsupported args: %s' % ' '.join(args)) |
3277 auth_config = auth.extract_auth_config_from_options(options) | 3284 auth_config = auth.extract_auth_config_from_options(options) |
3278 | 3285 |
3279 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) | 3286 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) |
3280 if not branches: | 3287 if not branches: |
3281 return 0 | 3288 return 0 |
(...skipping 11 matching lines...) Expand all Loading... |
3293 if status == 'closed'] | 3300 if status == 'closed'] |
3294 proposal.sort() | 3301 proposal.sort() |
3295 | 3302 |
3296 if not proposal: | 3303 if not proposal: |
3297 print('No branches with closed codereview issues found.') | 3304 print('No branches with closed codereview issues found.') |
3298 return 0 | 3305 return 0 |
3299 | 3306 |
3300 current_branch = GetCurrentBranch() | 3307 current_branch = GetCurrentBranch() |
3301 | 3308 |
3302 print('\nBranches with closed issues that will be archived:\n') | 3309 print('\nBranches with closed issues that will be archived:\n') |
3303 print('%*s | %s' % (alignment, 'Branch name', 'Archival tag name')) | 3310 if options.notags: |
3304 for next_item in proposal: | 3311 for next_item in proposal: |
3305 print('%*s %s' % (alignment, next_item[0], next_item[1])) | 3312 print(' ' + next_item[0]) |
| 3313 else: |
| 3314 print('%*s | %s' % (alignment, 'Branch name', 'Archival tag name')) |
| 3315 for next_item in proposal: |
| 3316 print('%*s %s' % (alignment, next_item[0], next_item[1])) |
3306 | 3317 |
3307 if any(branch == current_branch for branch, _ in proposal): | 3318 # Quit now on precondition failure or if instructed by the user, either |
| 3319 # via an interactive prompt or by command line flags. |
| 3320 if options.dry_run: |
| 3321 print('\nNo changes were made (dry run).\n') |
| 3322 return 0 |
| 3323 elif any(branch == current_branch for branch, _ in proposal): |
3308 print('You are currently on a branch \'%s\' which is associated with a ' | 3324 print('You are currently on a branch \'%s\' which is associated with a ' |
3309 'closed codereview issue, so archive cannot proceed. Please ' | 3325 'closed codereview issue, so archive cannot proceed. Please ' |
3310 'checkout another branch and run this command again.' % | 3326 'checkout another branch and run this command again.' % |
3311 current_branch) | 3327 current_branch) |
3312 return 1 | 3328 return 1 |
3313 | 3329 elif not options.force: |
3314 if not options.force: | |
3315 answer = ask_for_data('\nProceed with deletion (Y/n)? ').lower() | 3330 answer = ask_for_data('\nProceed with deletion (Y/n)? ').lower() |
3316 if answer not in ('y', ''): | 3331 if answer not in ('y', ''): |
3317 print('Aborted.') | 3332 print('Aborted.') |
3318 return 1 | 3333 return 1 |
3319 | 3334 |
3320 for branch, tagname in proposal: | 3335 for branch, tagname in proposal: |
3321 RunGit(['tag', tagname, branch]) | 3336 if not options.notags: |
| 3337 RunGit(['tag', tagname, branch]) |
3322 RunGit(['branch', '-D', branch]) | 3338 RunGit(['branch', '-D', branch]) |
| 3339 |
3323 print('\nJob\'s done!') | 3340 print('\nJob\'s done!') |
3324 | 3341 |
3325 return 0 | 3342 return 0 |
3326 | 3343 |
3327 | 3344 |
3328 def CMDstatus(parser, args): | 3345 def CMDstatus(parser, args): |
3329 """Show status of changelists. | 3346 """Show status of changelists. |
3330 | 3347 |
3331 Colors are used to tell the state of the CL unless --fast is used: | 3348 Colors are used to tell the state of the CL unless --fast is used: |
3332 - Red not sent for review or broken | 3349 - Red not sent for review or broken |
(...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5201 if __name__ == '__main__': | 5218 if __name__ == '__main__': |
5202 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5219 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5203 # unit testing. | 5220 # unit testing. |
5204 fix_encoding.fix_encoding() | 5221 fix_encoding.fix_encoding() |
5205 setup_color.init() | 5222 setup_color.init() |
5206 try: | 5223 try: |
5207 sys.exit(main(sys.argv[1:])) | 5224 sys.exit(main(sys.argv[1:])) |
5208 except KeyboardInterrupt: | 5225 except KeyboardInterrupt: |
5209 sys.stderr.write('interrupted\n') | 5226 sys.stderr.write('interrupted\n') |
5210 sys.exit(1) | 5227 sys.exit(1) |
OLD | NEW |