Commit 609f395e authored by luqui@chromium.org's avatar luqui@chromium.org

Make git cl upload correctly track upstream refs when uploading to Gerrit

NOPRESUBMIT because it's broke on CQ, Cf. https://codereview.chromium.org/1124803002

BUG=478260
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1110293002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295124 0039d316-1c4b-4281-b951-d872f2087c98
parent 84ec4ace
...@@ -1702,9 +1702,10 @@ def GerritUpload(options, args, cl, change): ...@@ -1702,9 +1702,10 @@ def GerritUpload(options, args, cl, change):
# We assume the remote called "origin" is the one we want. # We assume the remote called "origin" is the one we want.
# It is probably not worthwhile to support different workflows. # It is probably not worthwhile to support different workflows.
gerrit_remote = 'origin' gerrit_remote = 'origin'
branch = 'master'
if options.target_branch: remote, remote_branch = cl.GetRemoteBranch()
branch = options.target_branch branch = GetTargetRef(remote, remote_branch, options.target_branch,
pending_prefix='')
change_desc = ChangeDescription( change_desc = ChangeDescription(
options.message or CreateDescriptionFromLog(args)) options.message or CreateDescriptionFromLog(args))
......
...@@ -581,7 +581,8 @@ class TestGitCl(TestCase): ...@@ -581,7 +581,8 @@ class TestGitCl(TestCase):
] ]
@staticmethod @staticmethod
def _gerrit_upload_calls(description, reviewers, squash): def _gerrit_upload_calls(description, reviewers, squash,
expected_upstream_ref='origin/refs/heads/master'):
calls = [ calls = [
((['git', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
...@@ -620,7 +621,8 @@ class TestGitCl(TestCase): ...@@ -620,7 +621,8 @@ class TestGitCl(TestCase):
ref_to_push = 'HEAD' ref_to_push = 'HEAD'
calls += [ calls += [
((['git', 'rev-list', 'origin/master..' + ref_to_push],), ''), ((['git', 'rev-list',
expected_upstream_ref + '..' + ref_to_push],), ''),
((['git', 'config', 'rietveld.cc'],), '') ((['git', 'config', 'rietveld.cc'],), '')
] ]
receive_pack = '--receive-pack=git receive-pack ' receive_pack = '--receive-pack=git receive-pack '
...@@ -632,7 +634,8 @@ class TestGitCl(TestCase): ...@@ -632,7 +634,8 @@ class TestGitCl(TestCase):
receive_pack += '' receive_pack += ''
calls += [ calls += [
((['git', ((['git',
'push', receive_pack, 'origin', ref_to_push + ':refs/for/master'],), 'push', receive_pack, 'origin',
ref_to_push + ':refs/for/refs/heads/master'],),
'') '')
] ]
if squash: if squash:
...@@ -650,10 +653,13 @@ class TestGitCl(TestCase): ...@@ -650,10 +653,13 @@ class TestGitCl(TestCase):
upload_args, upload_args,
description, description,
reviewers, reviewers,
squash=False): squash=False,
expected_upstream_ref='origin/refs/heads/master'):
"""Generic gerrit upload test framework.""" """Generic gerrit upload test framework."""
self.calls = self._gerrit_base_calls() self.calls = self._gerrit_base_calls()
self.calls += self._gerrit_upload_calls(description, reviewers, squash) self.calls += self._gerrit_upload_calls(
description, reviewers, squash,
expected_upstream_ref=expected_upstream_ref)
git_cl.main(['upload'] + upload_args) git_cl.main(['upload'] + upload_args)
def test_gerrit_upload_without_change_id(self): def test_gerrit_upload_without_change_id(self):
...@@ -686,7 +692,8 @@ class TestGitCl(TestCase): ...@@ -686,7 +692,8 @@ class TestGitCl(TestCase):
['--squash'], ['--squash'],
'desc\n\nBUG=\nChange-Id:123456789\n', 'desc\n\nBUG=\nChange-Id:123456789\n',
[], [],
squash=True) squash=True,
expected_upstream_ref='origin/master')
def test_config_gerrit_download_hook(self): def test_config_gerrit_download_hook(self):
self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment