git_cl: Add the ability to set the description.

BUG=607359

Review-Url: https://codereview.chromium.org/1922133006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@300357 0039d316-1c4b-4281-b951-d872f2087c98
parent 37b07a78
......@@ -3279,6 +3279,8 @@ def CMDdescription(parser, args):
"""Brings up the editor for the current CL's description."""
parser.add_option('-d', '--display', action='store_true',
help='Display the description instead of opening an editor')
parser.add_option('-n', '--new-description',
help='New description to set for this issue (- for stdin)')
_add_codereview_select_options(parser)
auth.add_auth_options(parser)
......@@ -3302,10 +3304,20 @@ def CMDdescription(parser, args):
if not cl.GetIssue():
DieWithError('This branch has no associated changelist.')
description = ChangeDescription(cl.GetDescription())
if options.display:
print description.description
return 0
description.prompt()
if options.new_description:
text = options.new_description
if text == '-':
text = '\n'.join(sys.stdin.splitlines())
description.set_description(text)
else:
description.prompt()
if cl.GetDescription() != description.description:
cl.UpdateDescription(description.description)
return 0
......
......@@ -21,6 +21,19 @@ import git_common
import git_footers
import subprocess2
class ChangelistMock():
# A class variable so we can access it when we don't have access to the
# instance that's being set.
desc = ""
def __init__(self, **kwargs):
pass
def GetIssue(self):
return 1
def GetDescription(self):
return ChangelistMock.desc
def UpdateDescription(self, desc):
ChangelistMock.desc = desc
class PresubmitMock(object):
def __init__(self, *args, **kwargs):
self.reviewers = []
......@@ -1385,15 +1398,8 @@ class TestGitCl(TestCase):
out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out)
class MockChangelist():
def __init__(self, **kwargs):
pass
def GetIssue(self):
return 1
def GetDescription(self):
return 'foo'
self.mock(git_cl, 'Changelist', MockChangelist)
self.mock(git_cl, 'Changelist', ChangelistMock)
ChangelistMock.desc = 'foo\n'
self.assertEqual(0, git_cl.main(['description', '-d']))
self.assertEqual('foo\n', out.getvalue())
......@@ -1423,6 +1429,34 @@ class TestGitCl(TestCase):
'description', 'https://code.review.org/123123', '-d', '--gerrit']))
self.assertEqual('foobar\n', out.getvalue())
def test_description_set_raw(self):
out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out)
self.mock(git_cl, 'Changelist', ChangelistMock)
class TMP():
def splitlines(self):
return ['hihi']
self.mock(git_cl.sys, 'stdin', TMP())
self.assertEqual(0, git_cl.main(['description', '-n', 'hihi']))
self.assertEqual('hihi', ChangelistMock.desc)
def test_description_set_stdin(self):
out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out)
self.mock(git_cl, 'Changelist', ChangelistMock)
class TMP():
def splitlines(self):
return ['hi', 'there']
self.mock(git_cl.sys, 'stdin', TMP())
self.assertEqual(0, git_cl.main(['description', '-n', '-']))
self.assertEqual('hi\nthere', ChangelistMock.desc)
if __name__ == '__main__':
git_cl.logging.basicConfig(
......
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