go

Avoiding the `master` branch is used in `go get`

yyagi

y-yagi

Posted on October 31, 2018

Avoiding the `master` branch is used in `go get`

go get retrieves the default branch of the package by default. This is often using the master branch. But the master branch is including work in progress code sometimes, so want to avoid to use it.
To solve this problem, there is an approach of dividing the default branch and the development branch. But this is just a little complex.

Other approaches to solving this problem, use a branch or tag named go1.
go get has a rule for looks for a branch of tag that matches the locally installed version of Go. It describes in the doc.

When checking out or updating a package, get looks for a branch or tag that matches the locally installed version of Go. The most important rule is that if the local installation is running version "go1", get searches for a branch or tag named "go1". If no such version exists it retrieves the default branch of the package.  

https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies

This is also can confirm in get.go. Below is the code of the corresponding part.

// selectTag returns the closest matching tag for a given version.
// Closest means the latest one that is not after the current release.
// Version "goX" (or "goX.Y" or "goX.Y.Z") matches tags of the same form.
// Version "release.rN" matches tags of the form "go.rN" (N being a floating-point number).
// Version "weekly.YYYY-MM-DD" matches tags like "go.weekly.YYYY-MM-DD".
//
// NOTE(rsc): Eventually we will need to decide on some logic here.
// For now, there is only "go1". This matches the docs in go help get.
func selectTag(goVersion string, tags []string) (match string) {
    for _, t := range tags {
        if t == "go1" {
            return "go1"
        }
    }
    return ""
} 

https://github.com/golang/go/blob/fde4b9ed14e339b5064373c1d4a73e211ec32ac4/src/cmd/go/internal/get/get.go#L541-L556

Unfortunately, we can use go1 tar or branch only now.

But can use go1 to control the version used. Let's try to use it.

💖 💪 🙅 🚩
yyagi
y-yagi

Posted on October 31, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024