侧边栏壁纸
博主头像
张种恩的技术小栈博主等级

行动起来,活在当下

  • 累计撰写 748 篇文章
  • 累计创建 65 个标签
  • 累计收到 39 条评论

目 录CONTENT

文章目录
Go

go-git 获取远程仓库分支名称列表

zze
zze
2023-10-26 / 0 评论 / 0 点赞 / 255 阅读 / 929 字

不定期更新相关视频,抖音点击左上角加号后扫一扫右方侧边栏二维码关注我~正在更新《Shell其实很简单》系列

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())
		}
	}
}
0

评论区