Bug: gogit checkout fails on repositories whose default branch is not master

Aperta Adatta ai principianti
#85 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@linuxsuren-fs ci sta già lavorando.

Dal 17/11/2026.

  • #93 di @linuxsuren-fs — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli

Direzione di ricerca

Inizia in cmd/checkout.go: il valore predefinito del flag --branch è impostato vicino alla riga 46 e il git.CloneOptions con ReferenceName viene costruito intorno alla riga 82, dove c.Flags().Changed("branch") è già usato più avanti. Vincola ReferenceName a quello stesso controllo in modo che non venga inviato alcun ref di branch quando il flag è stato lasciato com'è, mantenendo invariato il percorso del branch esplicito. Fatto significa che gogit checkout su un repo con un branch predefinito main esegue il clone correttamente, e i test di checkout esistenti continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Description

gogit checkout always clones with a hardcoded master reference — cmd/checkout.go:82:

if repo, err = git.PlainCloneContext(c.Context(), repoDir, false, &git.CloneOptions{
    ...
    ReferenceName: plumbing.NewBranchReferenceName(o.branch),  // o.branch defaults to "master"

with the flag default --branch master (line 46). For any repository whose default branch is not master (e.g. main, which is the GitHub default since 2020), the clone fails with:

failed to clone git repository '<url>' into '<dir>', error: couldn't find remote ref "refs/heads/master"

even though the user never asked for master.

How to reproduce

gogit checkout --url https://github.com/<any org with main default branch>/<repo> --target /tmp/repo

Suggested fix

When --branch was not explicitly set, clone without ReferenceName (go-git then checks out the remote HEAD / default branch), and only pass it when the user provided a branch. c.Flags().Changed("branch") is already used later in the function, so the same signal is available.

Expected behavior

gogit checkout should work on any repository regardless of its default branch name.

Lingua principale
Go
Stelle
19
Fork
3
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di LinuxSuRen/gogit

Tutte le issue di LinuxSuRen/gogit

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.