all repos

mugit @ 18538b5b9955c402fb8681c583b4d38267019c02

🐮 git server that your cow will love
2 files changed, 24 insertions(+), 25 deletions(-)
git: refactor fetcher
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-01-30 20:54:12 +0200
Change ID: ywzvsxsrkrppttvpyvkqlqyoysopvxlt
Parent: 94608d2
M internal/git/repo.go

@@ -280,36 +280,35 @@ return g.r.SetConfig(c)

} func (g *Repo) Fetch(remote string) error { - return g.FetchWithAuth(remote, "") + return g.fetch(remote, nil) } -// FetchWithAuth fetches but with auth. Works only with github's auth -func (g *Repo) FetchWithAuth(remote string, token string) error { +func (g *Repo) FetchFromGithubWithToken(remote, token string) error { + return g.fetch(remote, &http.BasicAuth{ + Username: token, + Password: "x-oauth-basic", + }) +} + +func (g *Repo) fetch(remote string, auth http.AuthMethod) error { rmt, err := g.r.Remote(remote) if err != nil { return fmt.Errorf("failed to get upstream remote: %w", err) } - opts := &git.FetchOptions{ - RefSpecs: []gitconfig.RefSpec{ - // fetch all branches - "+refs/heads/*:refs/heads/*", - "+refs/tags/*:refs/tags/*", - }, - Tags: git.AllTags, - Prune: true, - Force: true, + if ferr := rmt.Fetch( + &git.FetchOptions{ + RefSpecs: []gitconfig.RefSpec{ + // fetch all branches + "+refs/heads/*:refs/heads/*", + "+refs/tags/*:refs/tags/*", + }, + Auth: auth, + Tags: git.AllTags, + Prune: true, + Force: true, + }); ferr != nil && !errors.Is(ferr, git.NoErrAlreadyUpToDate) { + return fmt.Errorf("fetch failed: %w", ferr) } - - if token != "" { - opts.Auth = &http.BasicAuth{ - Username: token, - Password: "x-oauth-basic", - } - } - - if err := rmt.Fetch(opts); err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { - return fmt.Errorf("fetch failed: %w", err) - } - return nil + return err }
M internal/mirror/mirror.go

@@ -101,7 +101,7 @@ return err

} if w.isRemoteGithub(mi.RemoteURL) && w.c.Mirror.GithubToken != "" { - if err := repo.FetchWithAuth(mi.Remote, w.c.Mirror.GithubToken); err != nil { + if err := repo.FetchFromGithubWithToken(mi.Remote, w.c.Mirror.GithubToken); err != nil { slog.Error("mirror: fetch failed (authorized)", "repo", name, "err", err) return err }