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

Side by Side Diff: git_cl.py

Issue 1830313002: Use tracking remote name for gerrit upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 9 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 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 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 # whitespace. This code is not doing this, but it clearly won't decrease 2451 # whitespace. This code is not doing this, but it clearly won't decrease
2452 # entropy. 2452 # entropy.
2453 lines.append(message) 2453 lines.append(message)
2454 change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'], 2454 change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'],
2455 stdin='\n'.join(lines)) 2455 stdin='\n'.join(lines))
2456 return 'I%s' % change_hash.strip() 2456 return 'I%s' % change_hash.strip()
2457 2457
2458 2458
2459 def GerritUpload(options, args, cl, change): 2459 def GerritUpload(options, args, cl, change):
2460 """upload the current branch to gerrit.""" 2460 """upload the current branch to gerrit."""
2461 # We assume the remote called "origin" is the one we want.
2462 # It is probably not worthwhile to support different workflows.
2463 gerrit_remote = 'origin'
2464
2465 remote, remote_branch = cl.GetRemoteBranch() 2461 remote, remote_branch = cl.GetRemoteBranch()
2466 branch = GetTargetRef(remote, remote_branch, options.target_branch, 2462 branch = GetTargetRef(remote, remote_branch, options.target_branch,
2467 pending_prefix='') 2463 pending_prefix='')
2468 2464
2469 change_desc = ChangeDescription( 2465 change_desc = ChangeDescription(
2470 options.message or CreateDescriptionFromLog(args)) 2466 options.message or CreateDescriptionFromLog(args))
2471 if not change_desc.description: 2467 if not change_desc.description:
2472 print "\nDescription is empty. Aborting..." 2468 print "\nDescription is empty. Aborting..."
2473 return 1 2469 return 1
2474 2470
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 parent = cl.GetCommonAncestorWithUpstream() 2512 parent = cl.GetCommonAncestorWithUpstream()
2517 2513
2518 tree = RunGit(['rev-parse', 'HEAD:']).strip() 2514 tree = RunGit(['rev-parse', 'HEAD:']).strip()
2519 ref_to_push = RunGit(['commit-tree', tree, '-p', parent, 2515 ref_to_push = RunGit(['commit-tree', tree, '-p', parent,
2520 '-m', message]).strip() 2516 '-m', message]).strip()
2521 else: 2517 else:
2522 if not git_footers.get_footer_change_id(change_desc.description): 2518 if not git_footers.get_footer_change_id(change_desc.description):
2523 DownloadGerritHook(False) 2519 DownloadGerritHook(False)
2524 change_desc.set_description(AddChangeIdToCommitMessage(options, args)) 2520 change_desc.set_description(AddChangeIdToCommitMessage(options, args))
2525 ref_to_push = 'HEAD' 2521 ref_to_push = 'HEAD'
2526 parent = '%s/%s' % (gerrit_remote, branch) 2522 parent = '%s/%s' % (remote, branch)
2527 change_id = git_footers.get_footer_change_id(change_desc.description)[0] 2523 change_id = git_footers.get_footer_change_id(change_desc.description)[0]
2528 2524
2529 commits = RunGitSilent(['rev-list', '%s..%s' % (parent, 2525 commits = RunGitSilent(['rev-list', '%s..%s' % (parent,
2530 ref_to_push)]).splitlines() 2526 ref_to_push)]).splitlines()
2531 if len(commits) > 1: 2527 if len(commits) > 1:
2532 print('WARNING: This will upload %d commits. Run the following command ' 2528 print('WARNING: This will upload %d commits. Run the following command '
2533 'to see which commits will be uploaded: ' % len(commits)) 2529 'to see which commits will be uploaded: ' % len(commits))
2534 print('git log %s..%s' % (parent, ref_to_push)) 2530 print('git log %s..%s' % (parent, ref_to_push))
2535 print('You can also use `git squash-branch` to squash these into a single ' 2531 print('You can also use `git squash-branch` to squash these into a single '
2536 'commit.') 2532 'commit.')
(...skipping 10 matching lines...) Expand all
2547 if cc: 2543 if cc:
2548 receive_options += ['--cc=' + email for email in cc] 2544 receive_options += ['--cc=' + email for email in cc]
2549 if change_desc.get_reviewers(): 2545 if change_desc.get_reviewers():
2550 receive_options.extend( 2546 receive_options.extend(
2551 '--reviewer=' + email for email in change_desc.get_reviewers()) 2547 '--reviewer=' + email for email in change_desc.get_reviewers())
2552 2548
2553 git_command = ['push'] 2549 git_command = ['push']
2554 if receive_options: 2550 if receive_options:
2555 git_command.append('--receive-pack=git receive-pack %s' % 2551 git_command.append('--receive-pack=git receive-pack %s' %
2556 ' '.join(receive_options)) 2552 ' '.join(receive_options))
2557 git_command += [gerrit_remote, ref_to_push + ':refs/for/' + branch] 2553 git_command += [remote, ref_to_push + ':refs/for/' + branch]
2558 push_stdout = gclient_utils.CheckCallAndFilter( 2554 push_stdout = gclient_utils.CheckCallAndFilter(
2559 ['git'] + git_command, 2555 ['git'] + git_command,
2560 print_stdout=True, 2556 print_stdout=True,
2561 # Flush after every line: useful for seeing progress when running as 2557 # Flush after every line: useful for seeing progress when running as
2562 # recipe. 2558 # recipe.
2563 filter_fn=lambda _: sys.stdout.flush()) 2559 filter_fn=lambda _: sys.stdout.flush())
2564 2560
2565 if options.squash: 2561 if options.squash:
2566 regex = re.compile(r'remote:\s+https?://[\w\-\.\/]*/(\d+)\s.*') 2562 regex = re.compile(r'remote:\s+https?://[\w\-\.\/]*/(\d+)\s.*')
2567 change_numbers = [m.group(1) 2563 change_numbers = [m.group(1)
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 if __name__ == '__main__': 4262 if __name__ == '__main__':
4267 # These affect sys.stdout so do it outside of main() to simplify mocks in 4263 # These affect sys.stdout so do it outside of main() to simplify mocks in
4268 # unit testing. 4264 # unit testing.
4269 fix_encoding.fix_encoding() 4265 fix_encoding.fix_encoding()
4270 colorama.init() 4266 colorama.init()
4271 try: 4267 try:
4272 sys.exit(main(sys.argv[1:])) 4268 sys.exit(main(sys.argv[1:]))
4273 except KeyboardInterrupt: 4269 except KeyboardInterrupt:
4274 sys.stderr.write('interrupted\n') 4270 sys.stderr.write('interrupted\n')
4275 sys.exit(1) 4271 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