import (
"fmt"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"sort"
"testing"
)
func TestName(t *testing.T) {
rem := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
Name: "origin",
URLs: []string{"git地址"},
})
refs, err := rem.List(&git.ListOptions{
PeelingOption: git.AppendPeeled,
Auth: &githttp.BasicAuth{
Username: "git账号",
Password: "git密码",
},
})
if err != nil {
fmt.Println(err.Error())
return
}
var branchs []string
for _, ref := range refs {
if ref.Name().IsBranch() {
branchs = append(branchs, ref.Name().Short())
}
}
sort.Strings(branchs)
}