git cl: rework setting to auto-generate git number footers.

BUG=642493

Change-Id: I1c83c54f7ad938cf4abeadb42f8d9414521d6dc5
Reviewed-on: https://chromium-review.googlesource.com/414465
Reviewed-by: Sergiy Byelozyorov <sergiyb@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
changes/65/414465/4
Andrii Shyshkalov 9 years ago committed by Commit Bot
parent 813ec3c322
commit 5fb4774810

@ -760,7 +760,6 @@ class Settings(object):
self.project = None
self.force_https_commit_url = None
self.pending_ref_prefix = None
self.git_number_footer = None
def LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available."""
@ -996,14 +995,6 @@ class Settings(object):
'pending-ref-prefix', error_ok=True)
return self.pending_ref_prefix
def GetHasGitNumberFooter(self):
# TODO(tandrii): this has to be removed after Rietveld is read-only.
# see also bugs http://crbug.com/642493 and http://crbug.com/600469.
if not self.git_number_footer:
self.git_number_footer = self._GetRietveldConfig(
'git-number-footer', error_ok=True)
return self.git_number_footer
def _GetRietveldConfig(self, param, **kwargs):
return self._GetConfig('rietveld.' + param, **kwargs)
@ -1015,6 +1006,19 @@ class Settings(object):
return RunGit(['config', param], **kwargs).strip()
def ShouldGenerateGitNumberFooters():
"""Decides depending on codereview.settings file in the current checkout HEAD.
"""
# TODO(tandrii): this has to be removed after Rietveld is read-only.
# see also bugs http://crbug.com/642493 and http://crbug.com/600469.
cr_settings_file = FindCodereviewSettingsFile()
if not cr_settings_file:
return False
keyvals = gclient_utils.ParseCodereviewSettingsContent(
cr_settings_file.read())
return keyvals.get('generate-git-number-footers', '').lower() == 'true'
def ShortBranchName(branch):
"""Convert a name like 'refs/heads/foo' to just 'foo'."""
return branch.replace('refs/heads/', '', 1)
@ -3210,7 +3214,6 @@ def LoadCodereviewSettingsFromFile(fileobj):
SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
SetProperty('project', 'PROJECT', unset_error_ok=True)
SetProperty('pending-ref-prefix', 'PENDING_REF_PREFIX', unset_error_ok=True)
SetProperty('git-number-footer', 'GIT_NUMBER_FOOTER', unset_error_ok=True)
SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK',
unset_error_ok=True)

@ -370,8 +370,6 @@ class TestGitCl(TestCase):
((['git', 'config', '--unset-all', 'rietveld.project'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.pending-ref-prefix'],),
CERR1),
((['git', 'config', '--unset-all', 'rietveld.git-number-footer'],),
CERR1),
((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],),
CERR1),
((['git', 'config', 'gerrit.host', 'true'],), ''),
@ -930,6 +928,30 @@ class TestGitCl(TestCase):
]
git_cl.main(['land'])
def test_ShouldGenerateGitNumberFooters(self):
self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: StringIO.StringIO(
'generate-git-number-footers: true\n'
))
self.assertTrue(git_cl.ShouldGenerateGitNumberFooters())
self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: StringIO.StringIO(
'generate-git-number-footers: false\n'
))
self.assertFalse(git_cl.ShouldGenerateGitNumberFooters())
self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: StringIO.StringIO(
'generate-git-number-footers: anything but true is false\n'
))
self.assertFalse(git_cl.ShouldGenerateGitNumberFooters())
self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: StringIO.StringIO(
"whatever: ignored"
))
self.assertFalse(git_cl.ShouldGenerateGitNumberFooters())
self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: None)
self.assertFalse(git_cl.ShouldGenerateGitNumberFooters())
@classmethod
def _gerrit_ensure_auth_calls(cls, issue=None, skip_auth_check=False):
cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated']

Loading…
Cancel
Save