Adds support to edit description on git cl upload

git cl upload gets a new flag --edit-description, which allows user to
edit git commit message. It only works when updating existing CL.

Bug: 739928
Change-Id: Ia501dc31f32e1887a937d5df39aed03745376827
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2020591
Reviewed-by: Andrii Shyshkalov <tandrii@google.com>
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index e9d28b5..d70da9e 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -917,7 +917,7 @@
                            short_hostname='chromium',
                            labels=None, change_id=None, original_title=None,
                            final_description=None, gitcookies_exists=True,
-                           force=False):
+                           force=False, edit_description=None):
     if post_amend_description is None:
       post_amend_description = description
     cc = cc or []
@@ -983,6 +983,13 @@
             ((['git', 'config', 'core.editor'],), ''),
             ((['RunEditor'],), description),
           ]
+      # user wants to edit description
+      if edit_description:
+        calls += [
+          ((['git', 'config', 'rietveld.bug-prefix'],), ''),
+          ((['git', 'config', 'core.editor'],), ''),
+          ((['RunEditor'],), edit_description),
+        ]
       ref_to_push = 'abcdef0123456789'
       calls += [
         ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
@@ -1240,6 +1247,7 @@
       final_description=None,
       gitcookies_exists=True,
       force=False,
+      edit_description=None,
       fetched_description=None):
     """Generic gerrit upload test framework."""
     if squash_mode is None:
@@ -1311,7 +1319,8 @@
           original_title=original_title,
           final_description=final_description,
           gitcookies_exists=gitcookies_exists,
-          force=force)
+          force=force,
+          edit_description=edit_description)
     # Uncomment when debugging.
     # print('\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))))
     git_cl.main(['upload'] + upload_args)
@@ -1531,6 +1540,21 @@
         'Uploading may fail due to lack of permissions',
         git_cl.sys.stdout.getvalue())
 
+  def test_upload_change_description_editor(self):
+    fetched_description = 'foo\n\nChange-Id: 123456789'
+    description = 'bar\n\nChange-Id: 123456789'
+    self._run_gerrit_upload_test(
+        ['--squash', '--edit-description'],
+        description,
+        [],
+        fetched_description=fetched_description,
+        squash=True,
+        expected_upstream_ref='origin/master',
+        issue=123456,
+        change_id='123456789',
+        original_title='User input',
+        edit_description=description)
+
   def test_upload_branch_deps(self):
     self.mock(git_cl.sys, 'stdout', StringIO())
     def mock_run_git(*args, **_kwargs):