diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 6b738160..12d6be4f 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -1196,9 +1196,16 @@ def select_views( repo = upstream.parse_repo(url) if repo is None or (repo.host, repo.slug) in seen: continue - branch = branch_in_url(url) or (declared if field == "source" else None) + # A mirror carries the source's history, commits and branches alike: + # its pin is source_commit. It read `source_mirror_commit`, a field + # no profile carries, and fell back to profiled_date, which a bump + # never moves (eden judged from f6e76860 while pinned on d16735f5). + pin_field = "source" if field == "source_mirror" else field + branch = branch_in_url(url) or ( + declared if pin_field == "source" else None + ) pin, origin = resolve_pin( - profile, repo, cache_dir, offline, field, mode, branch + profile, repo, cache_dir, offline, pin_field, mode, branch ) if not pin: continue diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index b10ed1f9..d31adf31 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -250,6 +250,32 @@ class TestSourceMirror(unittest.TestCase): [("source_mirror", "", "https://codeberg.org/o/mirror")], ) + def test_the_mirror_reads_the_source_pin(self): + """eden's mirror was judged from profiled_date while source_commit, + which bumps advance, named another revision.""" + profile = { + "source": "https://git.eden-emu.dev/o/port", + "source_mirror": "https://codeberg.org/o/mirror", + "source_commit": "d16735f5", + "profiled_date": "2026-03-26", + "source_branch": "dev", + } + calls = [] + + def head(repo, cache_dir, offline, branch=None): + calls.append(("head", repo.host, branch)) + return None if repo.host == "git.eden-emu.dev" else "tip" + + def at(*args, **kwargs): + raise AssertionError("a declared pin needs no date lookup") + + with mock.patch.object(profile_sync.upstream, "resolve_head", head), \ + mock.patch.object(profile_sync.upstream, "resolve_commit_at", at): + views = profile_sync.select_views(profile, "unused", True) + self.assertEqual([(v.repo.host, v.pin) for v in views], + [("codeberg.org", "d16735f5")]) + self.assertIn(("head", "codeberg.org", "dev"), calls) + def test_a_profile_without_a_mirror_is_unchanged(self): profile = {"source": "https://github.com/o/port"} self.assertEqual(