1 files changed,
35 insertions(+),
7 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-11 18:34:32 +0200
Authored at:
2026-02-11 03:06:10 +0200
Change ID:
nmotszywowzoxluxxzmtqzplwnnzzqyy
Parent:
ce839cf
M
internal/git/repo.go
路路路 10 10 "github.com/go-git/go-git/v5" 11 11 "github.com/go-git/go-git/v5/plumbing" 12 12 "github.com/go-git/go-git/v5/plumbing/object" 13 + "github.com/go-git/go-git/v5/plumbing/transport" 13 14 "github.com/go-git/go-git/v5/plumbing/transport/http" 14 15 ) 15 16 路路路 61 62 62 63 // Init initializes a bare repo in path. 63 64 func Init(path string) error { 64 - _, err := git.PlainInit(path, true) 65 - return err 65 + if _, err := git.PlainInit(path, true); err != nil { 66 + return fmt.Errorf("failed to initialize repo: %w", err) 67 + } 68 + return nil 66 69 } 67 70 68 71 func (g *Repo) Name() string { 路路路 203 206 204 207 func (g *Repo) FetchFromGithubWithToken(token string) error { 205 208 return g.fetch(&http.BasicAuth{ 206 - Username: token, 207 - Password: "x-oauth-basic", 209 + Username: "x-access-token", // this can be anything but empty 210 + Password: token, 208 211 }) 209 212 } 210 213 211 -func (g *Repo) fetch(auth http.AuthMethod) error { 214 +func (g *Repo) fetch(auth transport.AuthMethod) error { 212 215 rmt, err := g.r.Remote(originRemote) 213 216 if err != nil { 214 217 return fmt.Errorf("failed to get remote: %w", err) 215 218 } 216 219 217 - return rmt.Fetch(&git.FetchOptions{ 220 + if err = rmt.Fetch(&git.FetchOptions{ 218 221 Auth: auth, 219 222 Tags: git.AllTags, 220 223 Prune: true, 221 224 Force: true, 222 - }) 225 + }); err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { 226 + return fmt.Errorf("failed to fetch: %w", err) 227 + } 228 + 229 + // for some reason fetch doesn't change head for empty repos 230 + if !g.IsEmpty() { 231 + return nil 232 + } 233 + 234 + refs, err := rmt.List(&git.ListOptions{Auth: auth}) 235 + if err != nil { 236 + return fmt.Errorf("failed to list references: %w", err) 237 + } 238 + 239 + for _, ref := range refs { 240 + if ref.Name() == plumbing.HEAD { 241 + if err := g.r.Storer.SetReference( 242 + plumbing.NewSymbolicReference(plumbing.HEAD, ref.Target()), 243 + ); err != nil { 244 + return fmt.Errorf("failed to set HEAD: %w", err) 245 + } 246 + break 247 + } 248 + } 249 + 250 + return nil 223 251 }