Bladeren bron

Clear existing Change-Ids from description if issue is 0

git cl upload may not create a new change even if issue is 0 because
of a leftover Change-Id footer in the commit message.

Bug: 1484251
Change-Id: Ibee0542e0f5a2cbf930b1882892fbb7640054b69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4880971
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Gavin Mak 1 jaar geleden
bovenliggende
commit
36d937d16d
2 gewijzigde bestanden met toevoegingen van 21 en 3 verwijderingen
  1. 7 1
      git_cl.py
  2. 14 2
      tests/git_cl_test.py

+ 7 - 1
git_cl.py

@@ -1788,6 +1788,12 @@ class Changelist(object):
         bug = options.bug
         fixed = options.fixed
         if not self.GetIssue():
+            # There isn't any issue attached, so we shouldn't keep existing
+            # Change-Ids in the description.
+            if git_footers.get_footer_change_id(description):
+                description = git_footers.remove_footer(description,
+                                                        'Change-Id')
+
             # Extract bug number from branch name, but only if issue is being
             # created. It must start with bug or fix, followed by _ or - and
             # number. Optionally, it may contain _ or - after number with
@@ -1829,7 +1835,7 @@ class Changelist(object):
     def _GetTitleForUpload(self, options, multi_change_upload=False):
         # type: (optparse.Values, Optional[bool]) -> str
 
-        # Getting titles for multipl commits is not supported so we return the
+        # Getting titles for multiple commits is not supported so we return the
         # default.
         if not options.squash or multi_change_upload or options.title:
             return options.title

+ 14 - 2
tests/git_cl_test.py

@@ -32,7 +32,6 @@ import gerrit_util
 import git_cl
 import git_common
 import git_footers
-import git_new_branch
 import owners_client
 import scm
 import subprocess2
@@ -847,7 +846,8 @@ class TestGitCl(unittest.TestCase):
             self.mockGit.config['gerrit.override-squash-uploads'] = (
                 'true' if squash_mode == 'override_squash' else 'false')
 
-        if not git_footers.get_footer_change_id(description) and not squash:
+        has_change_id = git_footers.get_footer_change_id(description)
+        if not squash and (not has_change_id or not issue):
             calls += [
                 (('DownloadGerritHook', False), ''),
             ]
@@ -1340,6 +1340,8 @@ class TestGitCl(unittest.TestCase):
         self._run_gerrit_upload_test(
             ['-r', 'foo@example.com', '--send-mail'],
             'desc ✔\n\nBUG=\n\nChange-Id: I123456789',
+            post_amend_description=
+            'desc ✔\n\nBUG=\nR=foo@example.com\n\nChange-Id: I123456789',
             reviewers=['foo@example.com'],
             squash=False,
             squash_mode='override_nosquash',
@@ -1352,6 +1354,8 @@ class TestGitCl(unittest.TestCase):
         self._run_gerrit_upload_test(
             ['-r', 'foo@example.com', '--send-email'],
             'desc ✔\n\nBUG=\n\nChange-Id: I123456789',
+            post_amend_description=
+            'desc ✔\n\nBUG=\nR=foo@example.com\n\nChange-Id: I123456789',
             reviewers=['foo@example.com'],
             squash=False,
             squash_mode='override_nosquash',
@@ -1378,6 +1382,14 @@ class TestGitCl(unittest.TestCase):
             title='Title',
             change_id='Ixxxx')
 
+    def test_gerrit_upload_resets_change_id(self):
+        self._run_gerrit_upload_test(
+            [],
+            'desc=\n\nChange-Id: Iyyy', [],
+            log_description='desc=\n\nChange-Id: Ixxx',
+            issue=None,
+            change_id='Iyyy')
+
     def test_gerrit_upload_force_sets_fixed(self):
         self._run_gerrit_upload_test(
             ['-x', '10000', '-f'],