feat: follow a fork's base as its upstream head

For a port that is a GitHub fork of its upstream, the upstream code it
carries is the merge base of the two, not upstream's HEAD. The bump moved
upstream_commit to upstream HEAD on snes9x, kronos, np2kai and others
whose pin was that base. The upstream view's head is now the merge base
GitHub's compare names, the way _follow_submodule already reads a
vendored submodule. Outside a fork network the HEAD stays.
This commit is contained in:
Abdessamad Derraz committed 2026-10-23 16:25:56 +02:00
1 parent 01a6daf653
commit 861b89dd44
4 files changed
+116 -1

No files matched your search

+40
View File
@@ -1181,6 +1181,12 @@ class TestBuildReport(unittest.TestCase):
profile_sync.upstream._http_text,
profile_sync.upstream.list_gitlinks,
profile_sync.upstream.current_slug,
profile_sync.upstream.fork_base,
)
self.fork_bases: dict[str, str] = {}
profile_sync.upstream.fork_base = (
lambda repo, sha, fork, fork_sha, cache_dir, offline=False:
self.fork_bases.get(fork_sha)
)
self.current_slugs: dict[str, str] = {}
profile_sync.upstream.current_slug = (
@@ -1243,6 +1249,7 @@ class TestBuildReport(unittest.TestCase):
profile_sync.upstream._http_text,
profile_sync.upstream.list_gitlinks,
profile_sync.upstream.current_slug,
profile_sync.upstream.fork_base,
) = self._orig
self.tmp.cleanup()
@@ -4789,6 +4796,39 @@ class UpstreamVendoredAsASubmodule(unittest.TestCase):
self.assertEqual(views[1].head, "nesbox-tip")
class UpstreamForkedByThePort(unittest.TestCase):
"""snes9x, kronos and np2kai pinned upstream_commit on the merge base of
upstream with the fork. Compared to upstream's own HEAD, a bump moved it
past anything the port carries."""
def _views(self, base):
from unittest import mock # noqa: PLC0415
fork = profile_sync.upstream.make_repo("github.com", "f", "port")
self.up = profile_sync.upstream.make_repo("github.com", "o", "up")
self.fork = fork
views = [
profile_sync.RepoView(fork, "src-pin", "src-head", "source_commit", "source"),
profile_sync.RepoView(self.up, "old-base", "up-tip", "upstream_commit", "upstream"),
]
with mock.patch.object(
profile_sync.upstream, "fork_base", return_value=base
) as asked:
followed = profile_sync._follow_fork_base(views, "cache", True)
return followed, asked
def test_the_upstream_head_is_the_fork_base(self):
views, asked = self._views("new-base")
self.assertEqual(views[1].head, "new-base")
self.assertEqual(
asked.call_args.args[:4], (self.up, "up-tip", self.fork, "src-head")
)
def test_a_port_outside_the_network_keeps_the_tip(self):
views, _ = self._views(None)
self.assertEqual(views[1].head, "up-tip")
class OfflineCacheMissIsNotGone(TestBuildReport):
"""Offline, a file the cache never stored came back as None and the
report read "GONE (absent at HEAD, no rename found)" for files that