git-cl-upload: write commit description to file

Bug: 780540
Change-Id: I85bf40d8faa482786589f9031e34f364342c06dd
Reviewed-on: https://chromium-review.googlesource.com/754003
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index af33313..54aadfa 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -12,6 +12,7 @@
 import os
 import StringIO
 import sys
+import tempfile
 import unittest
 import urlparse
 
@@ -31,6 +32,28 @@
 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):
   # A class variable so we can access it when we don't have access to the
   # instance that's being set.
@@ -92,8 +115,6 @@
     return 'Commented'
 
 
-
-
 class GitCheckoutMock(object):
   def __init__(self, *args, **kwargs):
     pass
@@ -161,6 +182,7 @@
       return (hosts_with_creds or {}).get(host)
   return CookiesAuthenticatorMock
 
+
 class MockChangelistWithBranchAndIssue():
   def __init__(self, branch, issue):
     self.branch = branch
@@ -1541,7 +1563,7 @@
         ((['git', 'rev-parse', 'HEAD:'],),  # `HEAD:` means HEAD's tree hash.
          '0123456789abcdef'),
         ((['git', 'commit-tree', '0123456789abcdef', '-p', parent,
-           '-m', description],),
+           '-F', '/tmp/named'],),
          ref_to_push),
       ]
     else:
@@ -1693,6 +1715,9 @@
         other_cl_owner=other_cl_owner,
         custom_cl_base=custom_cl_base)
     if fetched_status != 'ABANDONED':
+      self.mock(tempfile, 'NamedTemporaryFile', MakeNamedTemporaryFileMock(
+          expected_content=description))
+      self.mock(os, 'remove', lambda _: True)
       self.calls += self._gerrit_upload_calls(
           description, reviewers, squash,
           squash_mode=squash_mode,