From 1062500617a0fada2a99bb13e727668b78a2ad2d Mon Sep 17 00:00:00 2001 From: "tandrii@chromium.org" Date: Fri, 4 Mar 2016 20:03:47 +0000 Subject: [PATCH] git cl: stop downloading Gerrit commit-hook with --squash mode. BUG=579176 Review URL: https://codereview.chromium.org/1760063002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299117 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 5 +---- tests/git_cl_test.py | 40 +++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/git_cl.py b/git_cl.py index 1666f33dc..d236e8596 100755 --- a/git_cl.py +++ b/git_cl.py @@ -600,10 +600,6 @@ class Settings(object): cr_settings_file = FindCodereviewSettingsFile() if autoupdate != 'false' and cr_settings_file: LoadCodereviewSettingsFromFile(cr_settings_file) - # set updated to True to avoid infinite calling loop - # through DownloadGerritHook - self.updated = True - DownloadGerritHook(False) self.updated = True def GetDefaultServerUrl(self, error_ok=False): @@ -2244,6 +2240,7 @@ def GerritUpload(options, args, cl, change): '-m', message]).strip() else: if not git_footers.get_footer_change_id(change_desc.description): + DownloadGerritHook(False) AddChangeIdToCommitMessage(options, args) ref_to_push = 'HEAD' parent = '%s/%s' % (gerrit_remote, branch) diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index e4a412b79..6f0eea4af 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -582,7 +582,10 @@ class TestGitCl(TestCase): @classmethod def _gerrit_upload_calls(cls, description, reviewers, squash, - expected_upstream_ref='origin/refs/heads/master'): + expected_upstream_ref='origin/refs/heads/master', + post_amend_description=None): + if post_amend_description is None: + post_amend_description = description calls = [ ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), ((['git', 'log', '--pretty=format:%s\n\n%b', @@ -590,7 +593,12 @@ class TestGitCl(TestCase): description) ] if not git_footers.get_footer_change_id(description) and not squash: + # TODOOOOO calls += [ + # DownloadGerritHook(False) + ((False, ), + ''), + # Amending of commit message to get the Change-Id. ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],), description), @@ -598,7 +606,7 @@ class TestGitCl(TestCase): ''), ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],), - description) + post_amend_description) ] if squash: ref_to_push = 'abcdef0123456789' @@ -655,21 +663,25 @@ class TestGitCl(TestCase): description, reviewers, squash=False, - expected_upstream_ref='origin/refs/heads/master'): + expected_upstream_ref='origin/refs/heads/master', + post_amend_description=None): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls( description, reviewers, squash, - expected_upstream_ref=expected_upstream_ref) + expected_upstream_ref=expected_upstream_ref, + post_amend_description=post_amend_description) # Uncomment when debugging. # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) git_cl.main(['upload'] + upload_args) def test_gerrit_upload_without_change_id(self): + self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) self._run_gerrit_upload_test( [], 'desc\n\nBUG=\n', - []) + [], + post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') def test_gerrit_no_reviewer(self): self._run_gerrit_upload_test( @@ -818,14 +830,6 @@ class TestGitCl(TestCase): ((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],), ''), ((['git', 'config', 'gerrit.host', 'True'],), ''), - # DownloadHooks(False) - ((['git', 'config', 'gerrit.host'],), 'True'), - ((['git', 'rev-parse', '--show-cdup'],), ''), - ((commit_msg_path, os.X_OK,), False), - (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg', - commit_msg_path,), ''), - ((commit_msg_path,), True), - ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), # GetCodereviewSettingsInteractively ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), @@ -839,12 +843,18 @@ class TestGitCl(TestCase): (('Tree status URL:',), ''), ((['git', 'config', 'rietveld.viewvc-url'],), ''), (('ViewVC URL:',), ''), - # DownloadHooks(True) ((['git', 'config', 'rietveld.bug-prefix'],), ''), (('Bug Prefix:',), ''), ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), (('Run Post Upload Hook:',), ''), - ((commit_msg_path, os.X_OK,), True), + # DownloadGerritHook(False) + ((['git', 'config', 'gerrit.host'],), 'True'), + ((['git', 'rev-parse', '--show-cdup'],), ''), + ((commit_msg_path, os.X_OK,), False), + (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg', + commit_msg_path,), ''), + ((commit_msg_path,), True), + ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), ] git_cl.main(['config'])