mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-07-21 06:52:11 -05:00
[PR #317] [MERGED] fix(mirror): reuse existing same-source mirrors instead of creating suffixed duplicates #7231
Reference in New Issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/317
Author: @arunavo4
Created: 6/12/2026
Status: ✅ Merged
Merged: 6/13/2026
Merged by: @arunavo4
Base:
main← Head:fix/315-source-aware-reuse📝 Commits (1)
5d08467fix(mirror): reuse existing same-source mirrors instead of creating suffixed duplicates (#315)📊 Changes
6 files changed (+901 additions, -400 deletions)
View changed files
📝
src/lib/gitea-enhanced.ts(+6 -1)📝
src/lib/gitea.ts(+241 -96)📝
src/lib/scheduler-service.ts(+21 -0)➖
src/lib/starred-repos-handler.ts(+0 -303)➕
src/lib/utils/mirror-source-match.test.ts(+420 -0)➕
src/lib/utils/mirror-source-match.ts(+213 -0)📄 Description
Fixes #315. Part of #309 (strategy-change duplicates and phantom forks).
Problem
Starred repos got re-mirrored into a brand-new Gitea repo on every sync with incrementing names (
starred/immich,immich-immich-app,-1,-2, …), withmirroredLocationrepointed to the newest copy and older ones orphaned. The same root cause produced duplicates when changing mirror strategy/naming (#309) and forks being marked "mirrored" while pointing at another repo's mirror (#309).Root cause
generateUniqueRepoNameonly asked "does a repo with this name exist?" — never "is the existing repo already a mirror of this same source" — so a repo's own prior mirror counted as a collision and earned a new suffix every run.repository.mirroredLocationwas written but never read on the create path.failed(with its live mirror preserved), so the scheduler re-entered the create path every cycle.Historical note: a correct base-name reuse pre-check existed in
starred-repos-handler.tsbut that module was never imported by anything; #281 routed scheduled starred auto-mirror through the unprotected direct path.Fix
src/lib/utils/mirror-source-match.ts: clone-URL normalization (credentials/.git/case), source-identity matching via Gitea'soriginal_url, andfindExistingMirror(prefers recordedmirroredLocation, then the base name).mirrorGithubRepoToGitea,mirrorGitHubRepoToGiteaOrg) now reuse an existing same-source mirror before any name generation.generateUniqueRepoNameis source-aware: an occupied name that mirrors the SAME source is reused; suffixing only happens on a genuine different-source collision (preserves the #95/#236 behavior). Per-user DB claims still block cross-user reuse.failedrepo whose recorded location still resolves to a live same-source mirror is synced, not re-created.starred-repos-handler.ts.When Gitea doesn't expose
original_url, matching fails toward "collision" (legacy suffix behavior) rather than risking reuse of an unrelated repo.Testing
Reusing existing same-source mirror, pointed at the canonical repo, created no fourth copy, and was idempotent across repeated runs.original_urlconfirmed populated on real Gitea mirrors.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.