git-cl: Use scm.GIT.GetConfig in more places.

Bug: 1051631
Change-Id: I43460b72dfbc9c8210c2d8fdf5d29e876a5637f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2056648
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
changes/48/2056648/3
Edward Lemur 5 years ago committed by LUCI CQ
parent 5e1d29fce3
commit 269640724f

@ -793,20 +793,22 @@ class Settings(object):
self.git_editor = None self.git_editor = None
self.format_full_by_default = None self.format_full_by_default = None
def LazyUpdateIfNeeded(self): def _LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available.""" """Updates the settings from a codereview.settings file, if available."""
if not self.updated: if self.updated:
# The only value that actually changes the behavior is return
# autoupdate = "false". Everything else means "true".
autoupdate = RunGit(['config', 'rietveld.autoupdate'], # The only value that actually changes the behavior is
error_ok=True # autoupdate = "false". Everything else means "true".
).strip().lower() autoupdate = (
scm.GIT.GetConfig(self.GetRoot(), 'rietveld.autoupdate', '').lower())
cr_settings_file = FindCodereviewSettingsFile()
if autoupdate != 'false' and cr_settings_file: cr_settings_file = FindCodereviewSettingsFile()
LoadCodereviewSettingsFromFile(cr_settings_file) if autoupdate != 'false' and cr_settings_file:
cr_settings_file.close() LoadCodereviewSettingsFromFile(cr_settings_file)
self.updated = True cr_settings_file.close()
self.updated = True
@staticmethod @staticmethod
def GetRelativeRoot(): def GetRelativeRoot():
@ -819,45 +821,43 @@ class Settings(object):
def GetTreeStatusUrl(self, error_ok=False): def GetTreeStatusUrl(self, error_ok=False):
if not self.tree_status_url: if not self.tree_status_url:
error_message = ('You must configure your tree status URL by running ' self.tree_status_url = self._GetConfig('rietveld.tree-status-url')
'"git cl config".') if self.tree_status_url is None and not error_ok:
self.tree_status_url = self._GetConfig( DieWithError(
'rietveld.tree-status-url', error_ok=error_ok, 'You must configure your tree status URL by running '
error_message=error_message) '"git cl config".')
return self.tree_status_url return self.tree_status_url
def GetViewVCUrl(self): def GetViewVCUrl(self):
if not self.viewvc_url: if not self.viewvc_url:
self.viewvc_url = self._GetConfig('rietveld.viewvc-url', error_ok=True) self.viewvc_url = self._GetConfig('rietveld.viewvc-url')
return self.viewvc_url return self.viewvc_url
def GetBugPrefix(self): def GetBugPrefix(self):
return self._GetConfig('rietveld.bug-prefix', error_ok=True) return self._GetConfig('rietveld.bug-prefix')
def GetRunPostUploadHook(self): def GetRunPostUploadHook(self):
run_post_upload_hook = self._GetConfig( run_post_upload_hook = self._GetConfig(
'rietveld.run-post-upload-hook', error_ok=True) 'rietveld.run-post-upload-hook')
return run_post_upload_hook == "True" return run_post_upload_hook == "True"
def GetDefaultCCList(self): def GetDefaultCCList(self):
return self._GetConfig('rietveld.cc', error_ok=True) return self._GetConfig('rietveld.cc')
def GetIsGerrit(self): def GetIsGerrit(self):
"""Returns True if this repo is associated with Gerrit.""" """Returns True if this repo is associated with Gerrit."""
if self.is_gerrit is None: if self.is_gerrit is None:
self.is_gerrit = ( self.is_gerrit = self._GetConfig('gerrit.host').lower() == 'true'
self._GetConfig('gerrit.host', error_ok=True).lower() == 'true')
return self.is_gerrit return self.is_gerrit
def GetSquashGerritUploads(self): def GetSquashGerritUploads(self):
"""Returns True if uploads to Gerrit should be squashed by default.""" """Returns True if uploads to Gerrit should be squashed by default."""
if self.squash_gerrit_uploads is None: if self.squash_gerrit_uploads is None:
self.squash_gerrit_uploads = self.GetSquashGerritUploadsOverride() self.squash_gerrit_uploads = self.GetSquashGerritUploadsOverride()
if self.squash_gerrit_uploads is None: if self.squash_gerrit_uploads is None:
# Default is squash now (http://crbug.com/611892#c23). # Default is squash now (http://crbug.com/611892#c23).
self.squash_gerrit_uploads = not ( self.squash_gerrit_uploads = self._GetConfig(
RunGit(['config', '--bool', 'gerrit.squash-uploads'], 'gerrit.squash-uploads').lower() != 'false'
error_ok=True).strip() == 'false')
return self.squash_gerrit_uploads return self.squash_gerrit_uploads
def GetSquashGerritUploadsOverride(self): def GetSquashGerritUploadsOverride(self):
@ -866,8 +866,7 @@ class Settings(object):
Returns None if no override has been defined. Returns None if no override has been defined.
""" """
# See also http://crbug.com/611892#c23 # See also http://crbug.com/611892#c23
result = RunGit(['config', '--bool', 'gerrit.override-squash-uploads'], result = self._GetConfig('gerrit.override-squash-uploads').lower()
error_ok=True).strip()
if result == 'true': if result == 'true':
return True return True
if result == 'false': if result == 'false':
@ -878,9 +877,8 @@ class Settings(object):
"""Return True if EnsureAuthenticated should not be done for Gerrit """Return True if EnsureAuthenticated should not be done for Gerrit
uploads.""" uploads."""
if self.gerrit_skip_ensure_authenticated is None: if self.gerrit_skip_ensure_authenticated is None:
self.gerrit_skip_ensure_authenticated = ( self.gerrit_skip_ensure_authenticated = self._GetConfig(
RunGit(['config', '--bool', 'gerrit.skip-ensure-authenticated'], 'gerrit.skip-ensure-authenticated').lower() == 'true'
error_ok=True).strip() == 'true')
return self.gerrit_skip_ensure_authenticated return self.gerrit_skip_ensure_authenticated
def GetGitEditor(self): def GetGitEditor(self):
@ -889,17 +887,15 @@ class Settings(object):
# Git requires single quotes for paths with spaces. We need to replace # Git requires single quotes for paths with spaces. We need to replace
# them with double quotes for Windows to treat such paths as a single # them with double quotes for Windows to treat such paths as a single
# path. # path.
self.git_editor = self._GetConfig( self.git_editor = self._GetConfig('core.editor').replace('\'', '"')
'core.editor', error_ok=True).replace('\'', '"')
return self.git_editor or None return self.git_editor or None
def GetLintRegex(self): def GetLintRegex(self):
return (self._GetConfig('rietveld.cpplint-regex', error_ok=True) or return self._GetConfig('rietveld.cpplint-regex', DEFAULT_LINT_REGEX)
DEFAULT_LINT_REGEX)
def GetLintIgnoreRegex(self): def GetLintIgnoreRegex(self):
return (self._GetConfig('rietveld.cpplint-ignore-regex', error_ok=True) or return self._GetConfig(
DEFAULT_LINT_IGNORE_REGEX) 'rietveld.cpplint-ignore-regex', DEFAULT_LINT_IGNORE_REGEX)
def GetFormatFullByDefault(self): def GetFormatFullByDefault(self):
if self.format_full_by_default is None: if self.format_full_by_default is None:
@ -909,9 +905,9 @@ class Settings(object):
self.format_full_by_default = (result == 'true') self.format_full_by_default = (result == 'true')
return self.format_full_by_default return self.format_full_by_default
def _GetConfig(self, param, **kwargs): def _GetConfig(self, key, default=''):
self.LazyUpdateIfNeeded() self._LazyUpdateIfNeeded()
return RunGit(['config', param], **kwargs).strip() return scm.GIT.GetConfig(self.GetRoot(), key, default)
class _CQState(object): class _CQState(object):
@ -1234,7 +1230,7 @@ class Changelist(object):
return value return value
remote, _ = self.GetRemoteBranch() remote, _ = self.GetRemoteBranch()
url = RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() url = scm.GIT.GetConfig(settings.GetRoot(), 'remote.%s.url' % remote, '')
# Check if the remote url can be parsed as an URL. # Check if the remote url can be parsed as an URL.
host = urllib.parse.urlparse(url).netloc host = urllib.parse.urlparse(url).netloc
@ -1254,9 +1250,7 @@ class Changelist(object):
return None return None
cache_path = url cache_path = url
url = RunGit(['config', 'remote.%s.url' % remote], url = scm.GIT.GetConfig(url, 'remote.%s.url' % remote, '')
error_ok=True,
cwd=url).strip()
host = urllib.parse.urlparse(url).netloc host = urllib.parse.urlparse(url).netloc
if not host: if not host:

@ -112,10 +112,14 @@ class GitMocks(object):
def NewBranch(self, branchref): def NewBranch(self, branchref):
self.branchref = branchref self.branchref = branchref
def GetConfig(self, _root, key, default=None): def GetConfig(self, root, key, default=None):
if root != '':
key = '%s:%s' % (root, key)
return self.config.get(key, default) return self.config.get(key, default)
def SetConfig(self, _root, key, value=None): def SetConfig(self, root, key, value=None):
if root != '':
key = '%s:%s' % (root, key)
if value: if value:
self.config[key] = value self.config[key] = value
return return
@ -707,12 +711,13 @@ class TestGitCl(unittest.TestCase):
'A few following expected calls:\n %s' % 'A few following expected calls:\n %s' %
(prior_calls, len(self._calls_done), expected_args, (prior_calls, len(self._calls_done), expected_args,
len(self._calls_done), args, following_calls)) len(self._calls_done), args, following_calls))
git_cl.logging.error(extended_msg)
self.fail('@%d\n' self.fail('@%d\n'
' Expected: %r\n' ' Expected: %r\n'
' Actual: %r' % ( ' Actual: %r\n'
len(self._calls_done), expected_args, args)) '\n'
'%s' % (
len(self._calls_done), expected_args, args, extended_msg))
self._calls_done.append(top) self._calls_done.append(top)
if isinstance(result, Exception): if isinstance(result, Exception):
@ -748,18 +753,6 @@ class TestGitCl(unittest.TestCase):
] ]
self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file)) self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file))
@classmethod
def _is_gerrit_calls(cls, gerrit=False):
return [((['git', 'config', 'rietveld.autoupdate'],), ''),
((['git', 'config', 'gerrit.host'],), 'True' if gerrit else '')]
@classmethod
def _git_post_upload_calls(cls):
return [
((['git', 'rev-parse', 'HEAD'],), 'hash'),
((['git', 'config', 'rietveld.run-post-upload-hook'],), ''),
]
@staticmethod @staticmethod
def _git_sanity_checks(diff_base, working_branch, get_remote_branch=True): def _git_sanity_checks(diff_base, working_branch, get_remote_branch=True):
fake_ancestor = 'fake_ancestor' fake_ancestor = 'fake_ancestor'
@ -786,30 +779,12 @@ class TestGitCl(unittest.TestCase):
'refs/remotes/origin/master'],), ''), 'refs/remotes/origin/master'],), ''),
] ]
@classmethod
def _gerrit_ensure_auth_calls(
cls, issue=None, skip_auth_check=False, short_hostname='chromium',
custom_cl_base=None):
cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated']
if skip_auth_check:
return [((cmd, ), 'true')]
calls = [((cmd, ), CERR1)]
calls.extend([
((['git', 'config', 'remote.origin.url'],),
'https://%s.googlesource.com/my/repo' % short_hostname)
])
return calls
@classmethod @classmethod
def _gerrit_base_calls(cls, issue=None, fetched_description=None, def _gerrit_base_calls(cls, issue=None, fetched_description=None,
fetched_status=None, other_cl_owner=None, fetched_status=None, other_cl_owner=None,
custom_cl_base=None, short_hostname='chromium', custom_cl_base=None, short_hostname='chromium',
change_id=None): change_id=None):
calls = cls._is_gerrit_calls(True) calls = []
if custom_cl_base: if custom_cl_base:
ancestor_revision = custom_cl_base ancestor_revision = custom_cl_base
else: else:
@ -820,11 +795,6 @@ class TestGitCl(unittest.TestCase):
ancestor_revision), ancestor_revision),
] ]
# Calls to verify branch point is ancestor
calls += cls._gerrit_ensure_auth_calls(
issue=issue, short_hostname=short_hostname,
custom_cl_base=custom_cl_base)
if issue: if issue:
calls += [ calls += [
(('GetChangeDetail', '%s-review.googlesource.com' % short_hostname, (('GetChangeDetail', '%s-review.googlesource.com' % short_hostname,
@ -882,8 +852,7 @@ class TestGitCl(unittest.TestCase):
] ]
return calls return calls
@classmethod def _gerrit_upload_calls(self, description, reviewers, squash,
def _gerrit_upload_calls(cls, description, reviewers, squash,
squash_mode='default', squash_mode='default',
expected_upstream_ref='origin/refs/heads/master', expected_upstream_ref='origin/refs/heads/master',
title=None, notify=False, title=None, notify=False,
@ -901,18 +870,9 @@ class TestGitCl(unittest.TestCase):
calls = [] calls = []
if squash_mode == 'default': if squash_mode in ('override_squash', 'override_nosquash'):
calls.extend([ self.mockGit.config['gerrit.override-squash-uploads'] = (
((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), ''), 'true' if squash_mode == 'override_squash' else 'false')
((['git', 'config', '--bool', 'gerrit.squash-uploads'],), ''),
])
elif squash_mode in ('override_squash', 'override_nosquash'):
calls.extend([
((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],),
'true' if squash_mode == 'override_squash' else 'false'),
])
else:
assert squash_mode in ('squash', 'nosquash')
# If issue is given, then description is fetched from Gerrit instead. # If issue is given, then description is fetched from Gerrit instead.
if issue is None: if issue is None:
@ -945,24 +905,13 @@ class TestGitCl(unittest.TestCase):
] ]
if squash: if squash:
if force or not issue: if force or not issue:
if issue:
calls += [
((['git', 'config', 'rietveld.bug-prefix'],), ''),
]
# Prompting to edit description on first upload.
calls += [
((['git', 'config', 'rietveld.bug-prefix'],), ''),
]
if not force: if not force:
calls += [ calls += [
((['git', 'config', 'core.editor'],), ''),
((['RunEditor'],), description), ((['RunEditor'],), description),
] ]
# user wants to edit description # user wants to edit description
if edit_description: if edit_description:
calls += [ calls += [
((['git', 'config', 'rietveld.bug-prefix'],), ''),
((['git', 'config', 'core.editor'],), ''),
((['RunEditor'],), edit_description), ((['RunEditor'],), edit_description),
] ]
ref_to_push = 'abcdef0123456789' ref_to_push = 'abcdef0123456789'
@ -1022,10 +971,6 @@ class TestGitCl(unittest.TestCase):
ref_suffix += ',m=' + title ref_suffix += ',m=' + title
metrics_arguments.append('m') metrics_arguments.append('m')
if issue is None:
calls += [
((['git', 'config', 'rietveld.cc'],), ''),
]
if short_hostname == 'chromium': if short_hostname == 'chromium':
# All reviwers and ccs get into ref_suffix. # All reviwers and ccs get into ref_suffix.
for r in sorted(reviewers): for r in sorted(reviewers):
@ -1183,7 +1128,9 @@ class TestGitCl(unittest.TestCase):
notify), notify),
''), ''),
] ]
calls += cls._git_post_upload_calls() calls += [
((['git', 'rev-parse', 'HEAD'],), 'hash'),
]
return calls return calls
def _run_gerrit_upload_test( def _run_gerrit_upload_test(
@ -1256,6 +1203,7 @@ class TestGitCl(unittest.TestCase):
mock.patch('os.path.isfile', mock.patch('os.path.isfile',
lambda path: self._mocked_call(['os.path.isfile', path])).start() lambda path: self._mocked_call(['os.path.isfile', path])).start()
self.mockGit.config['gerrit.host'] = 'true'
self.mockGit.config['branch.master.gerritissue'] = ( self.mockGit.config['branch.master.gerritissue'] = (
str(issue) if issue else None) str(issue) if issue else None)
self.mockGit.config['remote.origin.url'] = ( self.mockGit.config['remote.origin.url'] = (
@ -1295,14 +1243,10 @@ class TestGitCl(unittest.TestCase):
# print('\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))) # print('\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))))
git_cl.main(['upload'] + upload_args) git_cl.main(['upload'] + upload_args)
if squash: if squash:
self.assertEqual( self.assertIssueAndPatchset(patchset=None)
'123456', scm.GIT.GetBranchConfig(None, 'master', 'gerritissue'))
self.assertEqual(
'https://chromium-review.googlesource.com',
scm.GIT.GetBranchConfig(None, 'master', 'gerritserver'))
self.assertEqual( self.assertEqual(
'abcdef0123456789', 'abcdef0123456789',
scm.GIT.GetBranchConfig(None, 'master', 'gerritsquashhash')) scm.GIT.GetBranchConfig('', 'master', 'gerritsquashhash'))
def test_gerrit_upload_traces_no_gitcookies(self): def test_gerrit_upload_traces_no_gitcookies(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
@ -1759,19 +1703,19 @@ class TestGitCl(unittest.TestCase):
self, branch='master', issue='123456', patchset='7', self, branch='master', issue='123456', patchset='7',
git_short_host='chromium'): git_short_host='chromium'):
self.assertEqual( self.assertEqual(
issue, scm.GIT.GetBranchConfig(None, branch, 'gerritissue')) issue, scm.GIT.GetBranchConfig('', branch, 'gerritissue'))
self.assertEqual( self.assertEqual(
patchset, scm.GIT.GetBranchConfig(None, branch, 'gerritpatchset')) patchset, scm.GIT.GetBranchConfig('', branch, 'gerritpatchset'))
self.assertEqual( self.assertEqual(
'https://%s-review.googlesource.com' % git_short_host, 'https://%s-review.googlesource.com' % git_short_host,
scm.GIT.GetBranchConfig(None, branch, 'gerritserver')) scm.GIT.GetBranchConfig('', branch, 'gerritserver'))
def _patch_common(self, git_short_host='chromium'): def _patch_common(self, git_short_host='chromium'):
mock.patch('git_cl.IsGitVersionAtLeast', return_value=True).start() mock.patch('git_cl.IsGitVersionAtLeast', return_value=True).start()
self.mockGit.config['remote.origin.url'] = (
'https://%s.googlesource.com/my/repo' % git_short_host)
self.calls += [ self.calls += [
((['git', 'config', 'remote.origin.url'],),
'https://%s.googlesource.com/my/repo' % git_short_host),
(('GetChangeDetail', git_short_host + '-review.googlesource.com', (('GetChangeDetail', git_short_host + '-review.googlesource.com',
'my%2Frepo~123456', ['ALL_REVISIONS', 'CURRENT_COMMIT']), 'my%2Frepo~123456', ['ALL_REVISIONS', 'CURRENT_COMMIT']),
{ {
@ -1869,9 +1813,9 @@ class TestGitCl(unittest.TestCase):
'git_cl.gerrit_util.GetChangeDetail', 'git_cl.gerrit_util.GetChangeDetail',
side_effect=gerrit_util.GerritError(404, '')) side_effect=gerrit_util.GerritError(404, ''))
def test_patch_gerrit_not_exists(self, *_mocks): def test_patch_gerrit_not_exists(self, *_mocks):
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/my/repo')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/my/repo'),
(('DieWithError', (('DieWithError',
'change 123456 at https://chromium-review.googlesource.com does not ' 'change 123456 at https://chromium-review.googlesource.com does not '
'exist or you have no access to it'), SystemExitMock()), 'exist or you have no access to it'), SystemExitMock()),
@ -1906,11 +1850,11 @@ class TestGitCl(unittest.TestCase):
] ]
self.assertEqual(1, git_cl.main(['checkout', '99999'])) self.assertEqual(1, git_cl.main(['checkout', '99999']))
def _test_gerrit_ensure_authenticated_common(self, auth, def _test_gerrit_ensure_authenticated_common(self, auth):
skip_auth_check=False):
mock.patch('git_cl.gerrit_util.CookiesAuthenticator', mock.patch('git_cl.gerrit_util.CookiesAuthenticator',
CookiesAuthenticatorMockFactory(hosts_with_creds=auth)).start() CookiesAuthenticatorMockFactory(hosts_with_creds=auth)).start()
self.calls = self._gerrit_ensure_auth_calls(skip_auth_check=skip_auth_check) self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/my/repo')
cl = git_cl.Changelist() cl = git_cl.Changelist()
cl.branch = 'master' cl.branch = 'master'
cl.branchref = 'refs/heads/master' cl.branchref = 'refs/heads/master'
@ -1951,8 +1895,8 @@ class TestGitCl(unittest.TestCase):
self.assertIsNone(cl.EnsureAuthenticated(force=False)) self.assertIsNone(cl.EnsureAuthenticated(force=False))
def test_gerrit_ensure_authenticated_skipped(self): def test_gerrit_ensure_authenticated_skipped(self):
cl = self._test_gerrit_ensure_authenticated_common( self.mockGit.config['gerrit.skip-ensure-authenticated'] = 'true'
auth={}, skip_auth_check=True) cl = self._test_gerrit_ensure_authenticated_common(auth={})
self.assertIsNone(cl.EnsureAuthenticated(force=False)) self.assertIsNone(cl.EnsureAuthenticated(force=False))
def test_gerrit_ensure_authenticated_bearer_token(self): def test_gerrit_ensure_authenticated_bearer_token(self):
@ -1968,10 +1912,8 @@ class TestGitCl(unittest.TestCase):
self.assertTrue('Bearer' in header) self.assertTrue('Bearer' in header)
def test_gerrit_ensure_authenticated_non_https(self): def test_gerrit_ensure_authenticated_non_https(self):
self.mockGit.config['remote.origin.url'] = 'custom-scheme://repo'
self.calls = [ self.calls = [
((['git', 'config', '--bool',
'gerrit.skip-ensure-authenticated'],), CERR1),
((['git', 'config', 'remote.origin.url'],), 'custom-scheme://repo'),
(('logging.warning', (('logging.warning',
'Ignoring branch %(branch)s with non-https remote ' 'Ignoring branch %(branch)s with non-https remote '
'%(remote)s', { '%(remote)s', {
@ -1990,11 +1932,9 @@ class TestGitCl(unittest.TestCase):
self.assertIsNone(cl.EnsureAuthenticated(force=False)) self.assertIsNone(cl.EnsureAuthenticated(force=False))
def test_gerrit_ensure_authenticated_non_url(self): def test_gerrit_ensure_authenticated_non_url(self):
self.mockGit.config['remote.origin.url'] = (
'git@somehost.example:foo/bar.git')
self.calls = [ self.calls = [
((['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated'], ),
CERR1),
((['git', 'config', 'remote.origin.url'], ),
'git@somehost.example:foo/bar.git'),
(('logging.error', (('logging.error',
'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", ' 'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
'but it doesn\'t exist.', { 'but it doesn\'t exist.', {
@ -2017,9 +1957,9 @@ class TestGitCl(unittest.TestCase):
self.mockGit.config['branch.master.gerritissue'] = '123' self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = ( self.mockGit.config['branch.master.gerritserver'] = (
'https://chromium-review.googlesource.com') 'https://chromium-review.googlesource.com')
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/infra/infra.git'),
(('SetReview', 'chromium-review.googlesource.com', (('SetReview', 'chromium-review.googlesource.com',
'infra%2Finfra~123', None, 'infra%2Finfra~123', None,
{'Commit-Queue': vote}, notify, None), ''), {'Commit-Queue': vote}, notify, None), ''),
@ -2076,9 +2016,9 @@ class TestGitCl(unittest.TestCase):
git_cl.main(['set-close', '--issue', '1']), 0) git_cl.main(['set-close', '--issue', '1']), 0)
def test_description(self): def test_description(self):
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/my/repo')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/my/repo'),
(('GetChangeDetail', 'chromium-review.googlesource.com', (('GetChangeDetail', 'chromium-review.googlesource.com',
'my%2Frepo~123123', ['CURRENT_REVISION', 'CURRENT_COMMIT']), 'my%2Frepo~123123', ['CURRENT_REVISION', 'CURRENT_COMMIT']),
{ {
@ -2126,12 +2066,6 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start() mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start()
self.mockGit.config['branch.master.gerritissue'] = '123' self.mockGit.config['branch.master.gerritissue'] = '123'
self.calls = [
((['git', 'config', 'rietveld.autoupdate'],), CERR1),
((['git', 'config', 'rietveld.bug-prefix'],), CERR1),
((['git', 'config', 'core.editor'],), 'vi'),
]
self.assertEqual(0, git_cl.main(['description'])) self.assertEqual(0, git_cl.main(['description']))
def test_description_does_not_append_bug_line_if_fixed_is_present(self): def test_description_does_not_append_bug_line_if_fixed_is_present(self):
@ -2153,12 +2087,6 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start() mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start()
self.mockGit.config['branch.master.gerritissue'] = '123' self.mockGit.config['branch.master.gerritissue'] = '123'
self.calls = [
((['git', 'config', 'rietveld.autoupdate'],), CERR1),
((['git', 'config', 'rietveld.bug-prefix'],), CERR1),
((['git', 'config', 'core.editor'],), 'vi'),
]
self.assertEqual(0, git_cl.main(['description'])) self.assertEqual(0, git_cl.main(['description']))
def test_description_set_stdin(self): def test_description_set_stdin(self):
@ -2536,9 +2464,9 @@ class TestGitCl(unittest.TestCase):
def test_git_cl_comment_add_gerrit(self): def test_git_cl_comment_add_gerrit(self):
self.mockGit.branchref = None self.mockGit.branchref = None
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/infra/infra'),
(('SetReview', 'chromium-review.googlesource.com', 'infra%2Finfra~10', (('SetReview', 'chromium-review.googlesource.com', 'infra%2Finfra~10',
'msg', None, None, None), 'msg', None, None, None),
None), None),
@ -2547,9 +2475,9 @@ class TestGitCl(unittest.TestCase):
@mock.patch('git_cl.Changelist.GetBranch', return_value='foo') @mock.patch('git_cl.Changelist.GetBranch', return_value='foo')
def test_git_cl_comments_fetch_gerrit(self, *_mocks): def test_git_cl_comments_fetch_gerrit(self, *_mocks):
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/infra/infra'),
(('GetChangeDetail', 'chromium-review.googlesource.com', (('GetChangeDetail', 'chromium-review.googlesource.com',
'infra%2Finfra~1', 'infra%2Finfra~1',
['MESSAGES', 'DETAILED_ACCOUNTS', 'CURRENT_REVISION', ['MESSAGES', 'DETAILED_ACCOUNTS', 'CURRENT_REVISION',
@ -2690,9 +2618,9 @@ class TestGitCl(unittest.TestCase):
# git cl comments also fetches robot comments (which are considered a type # git cl comments also fetches robot comments (which are considered a type
# of autogenerated comment), and unlike other types of comments, only robot # of autogenerated comment), and unlike other types of comments, only robot
# comments from the latest patchset are shown. # comments from the latest patchset are shown.
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/infra/infra'),
(('GetChangeDetail', 'chromium-review.googlesource.com', (('GetChangeDetail', 'chromium-review.googlesource.com',
'infra%2Finfra~1', 'infra%2Finfra~1',
['MESSAGES', 'DETAILED_ACCOUNTS', 'CURRENT_REVISION', ['MESSAGES', 'DETAILED_ACCOUNTS', 'CURRENT_REVISION',
@ -2802,14 +2730,13 @@ class TestGitCl(unittest.TestCase):
mock.patch('os.path.isdir', selective_os_path_isdir_mock).start() mock.patch('os.path.isdir', selective_os_path_isdir_mock).start()
url = 'https://chromium.googlesource.com/my/repo' url = 'https://chromium.googlesource.com/my/repo'
self.mockGit.config['remote.origin.url'] = (
'/cache/this-dir-exists')
self.mockGit.config['/cache/this-dir-exists:remote.origin.url'] = (
url)
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'/cache/this-dir-exists'),
(('os.path.isdir', '/cache/this-dir-exists'), (('os.path.isdir', '/cache/this-dir-exists'),
True), True),
# Runs in /cache/this-dir-exists.
((['git', 'config', 'remote.origin.url'],),
url),
] ]
cl = git_cl.Changelist(issue=1) cl = git_cl.Changelist(issue=1)
self.assertEqual(cl.GetRemoteUrl(), url) self.assertEqual(cl.GetRemoteUrl(), url)
@ -2827,9 +2754,9 @@ class TestGitCl(unittest.TestCase):
mock.patch('logging.error', mock.patch('logging.error',
lambda *a: self._mocked_call('logging.error', *a)).start() lambda *a: self._mocked_call('logging.error', *a)).start()
self.mockGit.config['remote.origin.url'] = (
'/cache/this-dir-doesnt-exist')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'/cache/this-dir-doesnt-exist'),
(('os.path.isdir', '/cache/this-dir-doesnt-exist'), (('os.path.isdir', '/cache/this-dir-doesnt-exist'),
False), False),
(('logging.error', (('logging.error',
@ -2855,12 +2782,10 @@ class TestGitCl(unittest.TestCase):
mock.patch('logging.error', mock.patch('logging.error',
lambda *a: self._mocked_call('logging.error', *a)).start() lambda *a: self._mocked_call('logging.error', *a)).start()
self.mockGit.config['remote.origin.url'] = (
'/cache/this-dir-exists')
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],),
'/cache/this-dir-exists'),
(('os.path.isdir', '/cache/this-dir-exists'), True), (('os.path.isdir', '/cache/this-dir-exists'), True),
# Runs in /cache/this-dir-exists.
((['git', 'config', 'remote.origin.url'],), ''),
(('logging.error', (('logging.error',
'Remote "%(remote)s" for branch "%(branch)s" points to ' 'Remote "%(remote)s" for branch "%(branch)s" points to '
'"%(cache_path)s", but it is misconfigured.\n' '"%(cache_path)s", but it is misconfigured.\n'
@ -2875,10 +2800,8 @@ class TestGitCl(unittest.TestCase):
self.assertIsNone(cl.GetRemoteUrl()) self.assertIsNone(cl.GetRemoteUrl())
def test_gerrit_change_identifier_with_project(self): def test_gerrit_change_identifier_with_project(self):
self.calls = [ self.mockGit.config['remote.origin.url'] = (
((['git', 'config', 'remote.origin.url'],), 'https://chromium.googlesource.com/a/my/repo.git/')
'https://chromium.googlesource.com/a/my/repo.git/'),
]
cl = git_cl.Changelist(issue=123456) cl = git_cl.Changelist(issue=123456)
self.assertEqual(cl._GerritChangeIdentifier(), 'my%2Frepo~123456') self.assertEqual(cl._GerritChangeIdentifier(), 'my%2Frepo~123456')
@ -2887,7 +2810,6 @@ class TestGitCl(unittest.TestCase):
lambda *a: self._mocked_call('logging.error', *a)).start() lambda *a: self._mocked_call('logging.error', *a)).start()
self.calls = [ self.calls = [
((['git', 'config', 'remote.origin.url'],), CERR1),
(('logging.error', (('logging.error',
'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", ' 'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
'but it doesn\'t exist.', { 'but it doesn\'t exist.', {

Loading…
Cancel
Save