Bug: gogit checkout fails on repositories whose default branch is not master
評価
調査の方向性
cmd/checkout.go から開始します。--branch フラグのデフォルトは 46 行目付近で設定され、ReferenceName を持つ git.CloneOptions は 82 行目付近で構築されます。そこでは c.Flags().Changed("branch") がさらに下ですでに使われています。ReferenceName を同じチェックで条件付けし、フラグが変更されていない場合はブランチ ref を送信しないようにし、明示的なブランチの経路は変更しないままにします。完了とは、デフォルトブランチが main のリポジトリに対して gogit checkout が正常にクローンでき、既存の checkout テストも引き続き通ることを意味します。
索引モデルが issue の本文から書いたものです。
説明
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 ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
LinuxSuRen/gogit のほかの issue
-
Docs: replace the real-looking access token in README examples and fix build status help texts対応中かも @linuxsuren-fs が 7 日前に担当しました。 オープンdocumentation good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
LinuxSuRen/gogit#90 ·
-
Bug: --token file://… content is not trimmed, trailing newline breaks authentication対応中かも @linuxsuren-fs が 7 日前に担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
LinuxSuRen/gogit#87 ·
-
Bug: gogit checkout robustness: remotes[0] panic, wrong error message, empty version output, non-idempotent 0444 writes対応中かも @linuxsuren-fs が 7 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
LinuxSuRen/gogit#86 ·
-
Bug: DingTalk notification builds JSON by string concatenation, echoes the token, leaks resp.Body and swallows errors対応中かも @linuxsuren-fs が 7 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
LinuxSuRen/gogit#84 ·
-
Security: git access token is printed into pod logs by the Argo Workflows executor対応中かも @linuxsuren-fs が 7 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
LinuxSuRen/gogit#83 ·
LinuxSuRen/gogit の issue をすべて見る
似ている issue
-
Generated cask uses deprecated `postflight` stanza; Homebrew 7 warns on every command対応中かも @k4kratik が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sachincool/cruft#4 ·
-
help wanted kind/good-first-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
knative/func#4191 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
VictoriaMetrics/VictoriaLogs#1965 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug sig/ui
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kubermatic/dashboard#8540 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Sign-off cards drift between formats; write down one card format対応中かも @keyxmakerx が今日担当しました。 オープンdocumentation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
keyxmakerx/Chronicle#2795 ·
メンテナーはふだん 1 日以内に返信