Commit 9a03ae08 authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

git-cl-upload: write commit description to file

Bug: 780540
Change-Id: I85bf40d8faa482786589f9031e34f364342c06dd
Reviewed-on: https://chromium-review.googlesource.com/754003Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent c47ba1b0
...@@ -27,6 +27,7 @@ import re ...@@ -27,6 +27,7 @@ import re
import shutil import shutil
import stat import stat
import sys import sys
import tempfile
import textwrap import textwrap
import urllib import urllib
import urllib2 import urllib2
...@@ -3004,8 +3005,12 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -3004,8 +3005,12 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
parent = self._ComputeParent(remote, upstream_branch, custom_cl_base, parent = self._ComputeParent(remote, upstream_branch, custom_cl_base,
options.force, change_desc) options.force, change_desc)
tree = RunGit(['rev-parse', 'HEAD:']).strip() tree = RunGit(['rev-parse', 'HEAD:']).strip()
ref_to_push = RunGit(['commit-tree', tree, '-p', parent, with tempfile.NamedTemporaryFile(delete=False) as desc_tempfile:
'-m', change_desc.description]).strip() desc_tempfile.write(change_desc.description)
desc_tempfile.close()
ref_to_push = RunGit(['commit-tree', tree, '-p', parent,
'-F', desc_tempfile.name]).strip()
os.remove(desc_tempfile.name)
else: else:
change_desc = ChangeDescription( change_desc = ChangeDescription(
options.message or CreateDescriptionFromLog(git_diff_args)) options.message or CreateDescriptionFromLog(git_diff_args))
......
...@@ -12,6 +12,7 @@ import logging ...@@ -12,6 +12,7 @@ import logging
import os import os
import StringIO import StringIO
import sys import sys
import tempfile
import unittest import unittest
import urlparse import urlparse
...@@ -31,6 +32,28 @@ def callError(code=1, cmd='', cwd='', stdout='', stderr=''): ...@@ -31,6 +32,28 @@ def callError(code=1, cmd='', cwd='', stdout='', stderr=''):
CERR1 = callError(1) CERR1 = callError(1)
def MakeNamedTemporaryFileMock(expected_content):
class NamedTemporaryFileMock(object):
def __init__(self, *args, **kwargs):
self.name = '/tmp/named'
self.expected_content = expected_content
def __enter__(self):
return self
def __exit__(self, _type, _value, _tb):
pass
def write(self, content):
if self.expected_content:
assert content == self.expected_content
def close(self):
pass
return NamedTemporaryFileMock
class ChangelistMock(object): class ChangelistMock(object):
# A class variable so we can access it when we don't have access to the # A class variable so we can access it when we don't have access to the
# instance that's being set. # instance that's being set.
...@@ -92,8 +115,6 @@ class RietveldMock(object): ...@@ -92,8 +115,6 @@ class RietveldMock(object):
return 'Commented' return 'Commented'
class GitCheckoutMock(object): class GitCheckoutMock(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass pass
...@@ -161,6 +182,7 @@ def CookiesAuthenticatorMockFactory(hosts_with_creds=None, same_auth=False): ...@@ -161,6 +182,7 @@ def CookiesAuthenticatorMockFactory(hosts_with_creds=None, same_auth=False):
return (hosts_with_creds or {}).get(host) return (hosts_with_creds or {}).get(host)
return CookiesAuthenticatorMock return CookiesAuthenticatorMock
class MockChangelistWithBranchAndIssue(): class MockChangelistWithBranchAndIssue():
def __init__(self, branch, issue): def __init__(self, branch, issue):
self.branch = branch self.branch = branch
...@@ -1541,7 +1563,7 @@ class TestGitCl(TestCase): ...@@ -1541,7 +1563,7 @@ class TestGitCl(TestCase):
((['git', 'rev-parse', 'HEAD:'],), # `HEAD:` means HEAD's tree hash. ((['git', 'rev-parse', 'HEAD:'],), # `HEAD:` means HEAD's tree hash.
'0123456789abcdef'), '0123456789abcdef'),
((['git', 'commit-tree', '0123456789abcdef', '-p', parent, ((['git', 'commit-tree', '0123456789abcdef', '-p', parent,
'-m', description],), '-F', '/tmp/named'],),
ref_to_push), ref_to_push),
] ]
else: else:
...@@ -1693,6 +1715,9 @@ class TestGitCl(TestCase): ...@@ -1693,6 +1715,9 @@ class TestGitCl(TestCase):
other_cl_owner=other_cl_owner, other_cl_owner=other_cl_owner,
custom_cl_base=custom_cl_base) custom_cl_base=custom_cl_base)
if fetched_status != 'ABANDONED': if fetched_status != 'ABANDONED':
self.mock(tempfile, 'NamedTemporaryFile', MakeNamedTemporaryFileMock(
expected_content=description))
self.mock(os, 'remove', lambda _: True)
self.calls += self._gerrit_upload_calls( self.calls += self._gerrit_upload_calls(
description, reviewers, squash, description, reviewers, squash,
squash_mode=squash_mode, squash_mode=squash_mode,
......
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