mirror of
https://github.com/hanzoai/forge.git
synced 2026-11-23 05:50:59 +00:00
The inbound sync moved refs with update-ref, so none of what a push runs applied: no protected branches or tags, approvals, status checks, signatures or quota, no Actions, pull request checks or issue references. It also moved tags, resurrected branches deleted on the forge, and raised a notice per webhook. Inbound now fetches into a hidden refs/upstream namespace, records the tips before and after, and acts only on names whose tip changed. Each is one non-force git push from the repo to itself, under the pushing environment of [mirror] SYNC_USER, so pre-receive and post-receive run as for a person. No sync user, or one without write, or an archived repo, and nothing runs. A ref the forge refuses is reported and looked at again next time. Tags are create-only. A notice is raised once per distinct (ref, forge sha, upstream sha). The first sync of a repo with content only records upstream, since GitHub keeps every branch the forge deleted. refs/upstream is hidden from clients and closed to pushes in pre-receive. /v1/sync acts only on push, create and delete events, reads up to 25 MiB, and fails a database error rather than calling it "no mirror". The scheduled sweep also queues an inbound sync for each due push mirror to GitHub, so a missed event heals. The URL matcher moves to services/mirror and rejects ports, queries and odd paths. Push out takes no lock again, so a clone's inline pull never waits on it, and its LFS upload is bounded by the mirror timeout. The reconcile and announce split of the pull mirror is undone; only fetchableRemote is shared. Claude-Session: https://claude.ai/code/session_015XYKLo5aivJF2MHLneVUYc
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hanzoai/git/modules/log"
|
|
)
|
|
|
|
// Mirror settings
|
|
var Mirror = struct {
|
|
Enabled bool
|
|
DisableNewPull bool
|
|
DisableNewPush bool
|
|
DefaultInterval time.Duration
|
|
MinInterval time.Duration
|
|
|
|
// SyncSecret keys the HMAC on POST /v1/sync. Empty disables that route.
|
|
SyncSecret string
|
|
|
|
// SyncUser is the user the inbound sync pushes as, so branch protection and
|
|
// every other push check apply to it. Empty disables the inbound sync.
|
|
SyncUser string
|
|
}{
|
|
Enabled: true,
|
|
DisableNewPull: false,
|
|
DisableNewPush: false,
|
|
MinInterval: 10 * time.Minute,
|
|
DefaultInterval: 8 * time.Hour,
|
|
}
|
|
|
|
func loadMirrorFrom(rootCfg ConfigProvider) {
|
|
// Handle old configuration through `[repository]` `DISABLE_MIRRORS`
|
|
// - please note this was badly named and only disabled the creation of new pull mirrors
|
|
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
|
|
// if these are removed, the warning will not be shown
|
|
deprecatedSetting(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0")
|
|
if ConfigSectionKeyBool(rootCfg.Section("repository"), "DISABLE_MIRRORS") {
|
|
Mirror.DisableNewPull = true
|
|
}
|
|
|
|
if err := rootCfg.Section("mirror").MapTo(&Mirror); err != nil {
|
|
log.Fatal("Failed to map Mirror settings: %v", err)
|
|
}
|
|
|
|
Mirror.SyncSecret = rootCfg.Section("mirror").Key("SYNC_SECRET").String()
|
|
Mirror.SyncUser = rootCfg.Section("mirror").Key("SYNC_USER").String()
|
|
|
|
if !Mirror.Enabled {
|
|
Mirror.DisableNewPull = true
|
|
Mirror.DisableNewPush = true
|
|
}
|
|
|
|
if Mirror.MinInterval.Minutes() < 1 {
|
|
log.Warn("Mirror.MinInterval is too low, set to 1 minute")
|
|
Mirror.MinInterval = 1 * time.Minute
|
|
}
|
|
if Mirror.DefaultInterval < Mirror.MinInterval {
|
|
Mirror.DefaultInterval = max(time.Hour*8, Mirror.MinInterval)
|
|
log.Warn("Mirror.DefaultInterval is less than Mirror.MinInterval, set to %s", Mirror.DefaultInterval.String())
|
|
}
|
|
}
|