]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/go/internal/vcs/vcs.go
cmd/go/internal/vcs: error out if the requested repo does not support a secure protocol
[gostls13.git] / src / cmd / go / internal / vcs / vcs.go
index 4d6cdbca078570dfdc8154362ebbb523ad269483..8550f2a560e4eb3001f80a88d8b05beee3c0eaf5 100644 (file)
@@ -1171,18 +1171,31 @@ func repoRootFromVCSPaths(importPath string, security web.SecurityMode, vcsPaths
                        var ok bool
                        repoURL, ok = interceptVCSTest(repo, vcs, security)
                        if !ok {
-                               scheme := vcs.Scheme[0] // default to first scheme
-                               if vcs.PingCmd != "" {
-                                       // If we know how to test schemes, scan to find one.
+                               scheme, err := func() (string, error) {
                                        for _, s := range vcs.Scheme {
                                                if security == web.SecureOnly && !vcs.isSecureScheme(s) {
                                                        continue
                                                }
-                                               if vcs.Ping(s, repo) == nil {
-                                                       scheme = s
-                                                       break
+
+                                               // If we know how to ping URL schemes for this VCS,
+                                               // check that this repo works.
+                                               // Otherwise, default to the first scheme
+                                               // that meets the requested security level.
+                                               if vcs.PingCmd == "" {
+                                                       return s, nil
+                                               }
+                                               if err := vcs.Ping(s, repo); err == nil {
+                                                       return s, nil
                                                }
                                        }
+                                       securityFrag := ""
+                                       if security == web.SecureOnly {
+                                               securityFrag = "secure "
+                                       }
+                                       return "", fmt.Errorf("no %sprotocol found for repository", securityFrag)
+                               }()
+                               if err != nil {
+                                       return nil, err
                                }
                                repoURL = scheme + "://" + repo
                        }