mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to master@cbfd4023383d
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
47
vendor/github.com/moby/buildkit/util/gitutil/git_ref.go
generated
vendored
47
vendor/github.com/moby/buildkit/util/gitutil/git_ref.go
generated
vendored
@ -1,10 +1,11 @@
|
||||
package gitutil
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GitRef represents a git ref.
|
||||
@ -51,35 +52,51 @@ type GitRef struct {
|
||||
func ParseGitRef(ref string) (*GitRef, error) {
|
||||
res := &GitRef{}
|
||||
|
||||
var (
|
||||
remote *url.URL
|
||||
err error
|
||||
)
|
||||
|
||||
if strings.HasPrefix(ref, "github.com/") {
|
||||
res.IndistinguishableFromLocal = true // Deprecated
|
||||
} else {
|
||||
_, proto := ParseProtocol(ref)
|
||||
switch proto {
|
||||
case UnknownProtocol:
|
||||
return nil, errdefs.ErrInvalidArgument
|
||||
remote = &url.URL{
|
||||
Scheme: "https",
|
||||
Host: "github.com",
|
||||
Path: strings.TrimPrefix(ref, "github.com/"),
|
||||
}
|
||||
switch proto {
|
||||
} else {
|
||||
remote, err = ParseURL(ref)
|
||||
if errors.Is(err, ErrUnknownProtocol) {
|
||||
remote, err = ParseURL("https://" + ref)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch remote.Scheme {
|
||||
case HTTPProtocol, GitProtocol:
|
||||
res.UnencryptedTCP = true // Discouraged, but not deprecated
|
||||
}
|
||||
switch proto {
|
||||
|
||||
switch remote.Scheme {
|
||||
// An HTTP(S) URL is considered to be a valid git ref only when it has the ".git[...]" suffix.
|
||||
case HTTPProtocol, HTTPSProtocol:
|
||||
var gitURLPathWithFragmentSuffix = regexp.MustCompile(`\.git(?:#.+)?$`)
|
||||
if !gitURLPathWithFragmentSuffix.MatchString(ref) {
|
||||
if !strings.HasSuffix(remote.Path, ".git") {
|
||||
return nil, errdefs.ErrInvalidArgument
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fragment string
|
||||
res.Remote, fragment, _ = strings.Cut(ref, "#")
|
||||
if len(res.Remote) == 0 {
|
||||
return res, errdefs.ErrInvalidArgument
|
||||
res.Commit, res.SubDir = SplitGitFragment(remote.Fragment)
|
||||
remote.Fragment = ""
|
||||
|
||||
res.Remote = remote.String()
|
||||
if res.IndistinguishableFromLocal {
|
||||
_, res.Remote, _ = strings.Cut(res.Remote, "://")
|
||||
}
|
||||
res.Commit, res.SubDir, _ = strings.Cut(fragment, ":")
|
||||
|
||||
repoSplitBySlash := strings.Split(res.Remote, "/")
|
||||
res.ShortName = strings.TrimSuffix(repoSplitBySlash[len(repoSplitBySlash)-1], ".git")
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user