Commit 6eda05f9 authored by martiniss's avatar martiniss Committed by Commit bot

Allow git_cl to be called when no default server is given

Review-Url: https://codereview.chromium.org/2109253002
parent d0b10a0b
...@@ -1595,6 +1595,7 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase): ...@@ -1595,6 +1595,7 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
def __init__(self, changelist, auth_config=None, rietveld_server=None): def __init__(self, changelist, auth_config=None, rietveld_server=None):
super(_RietveldChangelistImpl, self).__init__(changelist) super(_RietveldChangelistImpl, self).__init__(changelist)
assert settings, 'must be initialized in _ChangelistCodereviewBase' assert settings, 'must be initialized in _ChangelistCodereviewBase'
if not rietveld_server:
settings.GetDefaultServerUrl() settings.GetDefaultServerUrl()
self._rietveld_server = rietveld_server self._rietveld_server = rietveld_server
...@@ -3448,17 +3449,23 @@ def CMDdescription(parser, args): ...@@ -3448,17 +3449,23 @@ def CMDdescription(parser, args):
target_issue = None target_issue = None
if len(args) > 0: if len(args) > 0:
issue_arg = ParseIssueNumberArgument(args[0]) target_issue = ParseIssueNumberArgument(args[0])
if not issue_arg.valid: if not target_issue.valid:
parser.print_help() parser.print_help()
return 1 return 1
target_issue = issue_arg.issue
auth_config = auth.extract_auth_config_from_options(options) auth_config = auth.extract_auth_config_from_options(options)
cl = Changelist( kwargs = {
auth_config=auth_config, issue=target_issue, 'auth_config': auth_config,
codereview=options.forced_codereview) 'codereview': options.forced_codereview,
}
if target_issue:
kwargs['issue'] = target_issue.issue
if options.forced_codereview == 'rietveld':
kwargs['rietveld_server'] = target_issue.hostname
cl = Changelist(**kwargs)
if not cl.GetIssue(): if not cl.GetIssue():
DieWithError('This branch has no associated changelist.') DieWithError('This branch has no associated changelist.')
......
...@@ -1493,14 +1493,8 @@ class TestGitCl(TestCase): ...@@ -1493,14 +1493,8 @@ class TestGitCl(TestCase):
def test_description_rietveld(self): def test_description_rietveld(self):
out = StringIO.StringIO() out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out) self.mock(git_cl.sys, 'stdout', out)
self.mock(git_cl.Changelist, 'GetDescription', self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'foobar')
lambda *args: 'foobar')
self.calls = [
((['git', 'config', 'rietveld.autoupdate'],), ''),
((['git', 'config', 'rietveld.server'],), ''),
((['git', 'config', 'rietveld.server'],), ''),
]
self.assertEqual(0, git_cl.main([ self.assertEqual(0, git_cl.main([
'description', 'https://code.review.org/123123', '-d', '--rietveld'])) 'description', 'https://code.review.org/123123', '-d', '--rietveld']))
self.assertEqual('foobar\n', out.getvalue()) self.assertEqual('foobar\n', out.getvalue())
...@@ -1508,8 +1502,7 @@ class TestGitCl(TestCase): ...@@ -1508,8 +1502,7 @@ class TestGitCl(TestCase):
def test_description_gerrit(self): def test_description_gerrit(self):
out = StringIO.StringIO() out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out) self.mock(git_cl.sys, 'stdout', out)
self.mock(git_cl.Changelist, 'GetDescription', self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'foobar')
lambda *args: 'foobar')
self.assertEqual(0, git_cl.main([ self.assertEqual(0, git_cl.main([
'description', 'https://code.review.org/123123', '-d', '--gerrit'])) 'description', 'https://code.review.org/123123', '-d', '--gerrit']))
......
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