summaryrefslogtreecommitdiffstats
path: root/tests/test_project.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_project.py')
-rw-r--r--tests/test_project.py46
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
141class ProjectTests(unittest.TestCase): 183class 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: