google 好久找不到,测出来了,记录一下。
package tests
import (
"fmt"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"testing"
)
func Test(t *testing.T) {
remote := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
URLs: []string{"https://github.com/zze326/devops-super.git"},
Mirror: false,
Fetch: nil,
})
refs, err := remote.List(&git.ListOptions{
Auth: &http.BasicAuth{
Username: "root",
Password: "123456",
},
InsecureSkipTLS: true,
Timeout: 0,
})
if err != nil {
t.Fatal(err)
}
// 遍历引用列表,过滤出分支引用并打印名称
for _, ref := range refs {
if name := ref.Name(); name.IsBranch() {
fmt.Println(name.Short())
}
}
}
评论区