git-cl: Use _create_description_from_log instead of GetLocalDescription

Also refactor code to eliminate multiple calls to _create_description_from_log.

Change-Id: I113134fbd90f396bdb6d561ed0369ea5ee9c78ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2090448
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index ed805b0..435e57d 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -852,8 +852,6 @@
     if post_amend_description is None:
       post_amend_description = description
     cc = cc or []
-    # Determined in `_gerrit_base_calls`.
-    determined_ancestor_revision = custom_cl_base or 'fake_ancestor_sha'
 
     calls = []
 
@@ -863,12 +861,6 @@
 
     # If issue is given, then description is fetched from Gerrit instead.
     if issue is None:
-      calls += [
-        ((['git', 'log', '--pretty=format:%s\n\n%b',
-           ((custom_cl_base + '..') if custom_cl_base else
-            'fake_ancestor_sha..HEAD')],),
-         description),
-      ]
       if squash:
         title = 'Initial_upload'
     else:
@@ -881,14 +873,6 @@
     if not git_footers.get_footer_change_id(description) and not squash:
       calls += [
         (('DownloadGerritHook', False), ''),
-        # Amending of commit message to get the Change-Id.
-        ((['git', 'log', '--pretty=format:%s\n\n%b',
-           determined_ancestor_revision + '..HEAD'],),
-         description),
-        ((['git', 'commit', '--amend', '-m', description],), ''),
-        ((['git', 'log', '--pretty=format:%s\n\n%b',
-           determined_ancestor_revision + '..HEAD'],),
-         post_amend_description)
       ]
     if squash:
       if force or not issue:
@@ -1192,7 +1176,10 @@
               lambda path: self._mocked_call(['os.path.isfile', path])).start()
     mock.patch('git_cl.Changelist.GitSanityChecks', return_value=True).start()
     mock.patch(
-        'git_cl.Changelist.GetLocalDescription', return_value='foo').start()
+        'git_cl._create_description_from_log', return_value=description).start()
+    mock.patch(
+        'git_cl.Changelist._AddChangeIdToCommitMessage',
+        return_value=post_amend_description or description).start()
     mock.patch(
         'git_cl.ask_for_data',
         lambda prompt: self._mocked_call('ask_for_data', prompt)).start()
@@ -2818,15 +2805,6 @@
     self.addCleanup(mock.patch.stopall)
     self.temp_count = 0
 
-  @mock.patch('git_cl.RunGitWithCode')
-  def testGetLocalDescription(self, _mock):
-    git_cl.RunGitWithCode.return_value = (0, 'description')
-    cl = git_cl.Changelist()
-    self.assertEqual('description', cl.GetLocalDescription('branch'))
-    self.assertEqual('description', cl.GetLocalDescription('branch'))
-    git_cl.RunGitWithCode.assert_called_once_with(
-        ['log', '--pretty=format:%s%n%n%b', 'branch...'])
-
   def testRunHook(self):
     expected_results = {
         'more_cc': ['more@example.com', 'cc@example.com'],
@@ -3031,7 +3009,7 @@
         'git_cl.Changelist.FetchDescription',
         return_value='fetch description').start()
     mock.patch(
-        'git_cl.Changelist.GetLocalDescription',
+        'git_cl._create_description_from_log',
         return_value='get description').start()
     mock.patch('git_cl.Changelist.RunHook').start()