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

オープン 初心者向け
#85 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@linuxsuren-fs がすでに取り組んでいます。

2026年11月17日 から。

  • #93 @linuxsuren-fs による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
cli

調査の方向性

cmd/checkout.go から開始します。--branch フラグのデフォルトは 46 行目付近で設定され、ReferenceName を持つ git.CloneOptions は 82 行目付近で構築されます。そこでは c.Flags().Changed("branch") がさらに下ですでに使われています。ReferenceName を同じチェックで条件付けし、フラグが変更されていない場合はブランチ ref を送信しないようにし、明示的なブランチの経路は変更しないままにします。完了とは、デフォルトブランチが main のリポジトリに対して gogit checkout が正常にクローンでき、既存の checkout テストも引き続き通ることを意味します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
19
フォーク
3
PR マージ指標
30日以内にマージされた PR はありません

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

LinuxSuRen/gogit のほかの issue

LinuxSuRen/gogit の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。