diff options
| author | Romaric Jodin <rjodin@google.com> | 2026-10-29 08:52:04 +0100 |
|---|---|---|
| committer | gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-11-03 00:10:19 -0800 |
| commit | 365629015667e04739f59070e745548a728549c8 (patch) | |
| tree | dc4fee64bdec9157fe232c5689a3763fbcb70057 /tests/test_project.py | |
| parent | b90c7cd8f9e14418c4a486f424fc9afc84d3ff18 (diff) | |
| download | git-repo-2.72.tar.gz | |
When uploading a branch that merges another remote-tracking branch (such
as an upstream branch into the destination branch), ReviewableBranch
only excludes the destination tracking branch (^base). As a result, git
rev-list walks the merged parent and counts all merged commits even
though they already exist on a remote branch, triggering the unusual
commit count warning in _VerifyPendingCommits.
Add --ignore-remote-commits to `repo upload` to pass --not --remotes to
git rev-list in ReviewableBranch so commits already reachable from
refs/remotes/* are excluded from the pending commit list.
Test: ./run_tests tests/test_project.py tests/test_subcmds_upload.py
Change-Id: Ib1fb864982729e20a621144580fe95daa478eaee
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/651284
Tested-by: Romaric Jodin <rjodin@google.com>
Reviewed-by: Brian Gan <brgan@google.com>
Commit-Queue: Romaric Jodin <rjodin@google.com>
Diffstat (limited to 'tests/test_project.py')
| -rw-r--r-- | tests/test_project.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/test_project.py b/tests/test_project.py index f65e83f95..82a90a6dc 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -137,6 +137,48 @@ class ReviewableBranchTests(unittest.TestCase): | |||
| 137 | 137 | ||
| 138 | self.assertTrue(rb.current) | 138 | self.assertTrue(rb.current) |
| 139 | 139 | ||
| 140 | def test_ignore_remote_commits(self) -> None: | ||
| 141 | """Check ignore_remote_commits excludes commits in refs/remotes/*.""" | ||
| 142 | with utils_for_test.TempGitTree() as tempdir: | ||
| 143 | fakeproj = FakeProject(tempdir) | ||
| 144 | |||
| 145 | with open(os.path.join(tempdir, "readme"), "w") as fp: | ||
| 146 | fp.write("init") | ||
| 147 | fakeproj.work_git.add("readme") | ||
| 148 | fakeproj.work_git.commit("-mInit") | ||
| 149 | |||
| 150 | # Create an upstream commit and record it under refs/remotes/. | ||
| 151 | fakeproj.work_git.checkout("-b", "upstream") | ||
| 152 | with open(os.path.join(tempdir, "upstream.txt"), "w") as fp: | ||
| 153 | fp.write("upstream") | ||
| 154 | fakeproj.work_git.add("upstream.txt") | ||
| 155 | fakeproj.work_git.commit("-mUpstream change") | ||
| 156 | fakeproj.work_git.update_ref( | ||
| 157 | "refs/remotes/upstream/main", "refs/heads/upstream" | ||
| 158 | ) | ||
| 159 | |||
| 160 | # Merge the remote branch into work on top of main. | ||
| 161 | fakeproj.work_git.checkout("-b", "work", "main") | ||
| 162 | fakeproj.work_git.merge( | ||
| 163 | "--no-ff", "-mMerge upstream", "refs/remotes/upstream/main" | ||
| 164 | ) | ||
| 165 | |||
| 166 | rb_default = project.ReviewableBranch( | ||
| 167 | fakeproj, fakeproj.config.GetBranch("work"), "main" | ||
| 168 | ) | ||
| 169 | self.assertEqual(2, len(rb_default.commits)) | ||
| 170 | self.assertEqual(2, len(rb_default.unabbrev_commits)) | ||
| 171 | |||
| 172 | rb_ignored = project.ReviewableBranch( | ||
| 173 | fakeproj, | ||
| 174 | fakeproj.config.GetBranch("work"), | ||
| 175 | "main", | ||
| 176 | ignore_remote_commits=True, | ||
| 177 | ) | ||
| 178 | self.assertEqual(1, len(rb_ignored.commits)) | ||
| 179 | self.assertIn("Merge upstream", rb_ignored.commits[0]) | ||
| 180 | self.assertEqual(1, len(rb_ignored.unabbrev_commits)) | ||
| 181 | |||
| 140 | 182 | ||
| 141 | class ProjectTests(unittest.TestCase): | 183 | class ProjectTests(unittest.TestCase): |
| 142 | """Check Project behavior.""" | 184 | """Check Project behavior.""" |
| @@ -1277,7 +1319,9 @@ class ProjectTests(unittest.TestCase): | |||
| 1277 | ) as mock_get_up: | 1319 | ) as mock_get_up: |
| 1278 | res = proj.GetUploadableBranches("feature") | 1320 | res = proj.GetUploadableBranches("feature") |
| 1279 | self.assertEqual(res, [mock_rb]) | 1321 | self.assertEqual(res, [mock_rb]) |
| 1280 | mock_get_up.assert_called_once_with("feature") | 1322 | mock_get_up.assert_called_once_with( |
| 1323 | "feature", ignore_remote_commits=False | ||
| 1324 | ) | ||
| 1281 | 1325 | ||
| 1282 | def _get_derived_subproject_url(self, submodule_url): | 1326 | def _get_derived_subproject_url(self, submodule_url): |
| 1283 | with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir: | 1327 | with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir: |
