nf/nft/tool/clone.go

41 lines
695 B
Go
Raw Permalink Normal View History

2024-12-26 19:40:39 +08:00
package tool
import (
"fmt"
2024-12-26 19:40:39 +08:00
"net/url"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/http"
)
2024-12-26 19:40:39 +08:00
func Clone(projectDir string, repoURL string) error {
ins, err := url.Parse(repoURL)
if err != nil {
return err
}
uri := fmt.Sprintf("%s://%s%s", ins.Scheme, ins.Host, ins.Path)
2024-12-26 19:40:39 +08:00
opt := &git.CloneOptions{
URL: uri,
Depth: 1,
InsecureSkipTLS: true,
SingleBranch: true,
}
if ins.User != nil {
password, _ := ins.User.Password()
opt.Auth = &http.BasicAuth{
Username: ins.User.Username(),
Password: password,
}
}
2024-12-26 19:40:39 +08:00
_, err = git.PlainClone(projectDir, false, opt)
if err != nil {
return err
}
return nil
}