@@ -231,6 +231,21 @@ func CleanOnError(err *error, path string) {
231231 }
232232}
233233
234+ func gitURLParse (gitURL string ) (* url.URL , error ) {
235+ parsedURL , originalError := url .Parse (gitURL )
236+ if originalError != nil {
237+ var err error
238+ gitURLBytes := []byte ("ssh://" + gitURL )
239+ colonIndex := bytes .LastIndex (gitURLBytes , []byte (":" ))
240+ gitURLBytes [colonIndex ] = byte ('/' )
241+ parsedURL , err = url .Parse (string (gitURLBytes ))
242+ if err != nil {
243+ return nil , originalError
244+ }
245+ }
246+ return parsedURL , nil
247+ }
248+
234249func CloneRepo (userInfo * url.Userinfo , gitUrl string , args ... string ) (clonePath string , repo * git.Repository , err error ) {
235250 if err = GitCmdCheck (); err != nil {
236251 return
@@ -241,12 +256,13 @@ func CloneRepo(userInfo *url.Userinfo, gitUrl string, args ...string) (clonePath
241256 return
242257 }
243258 defer CleanOnError (& err , clonePath )
244- cloneURL , err := url . Parse (gitUrl )
259+ cloneURL , err := gitURLParse (gitUrl )
245260 if err != nil {
246- err = errors .WrapPrefix (err , "could not parse url" , 0 )
247- return
261+ return "" , nil , err
262+ }
263+ if cloneURL .User == nil {
264+ cloneURL .User = userInfo
248265 }
249- cloneURL .User = userInfo
250266
251267 gitArgs := []string {"clone" , cloneURL .String (), clonePath }
252268 gitArgs = append (gitArgs , args ... )
@@ -651,7 +667,7 @@ func PrepareRepoSinceCommit(uriString, commitHash string) (string, bool, error)
651667 // the uriString is github.com, then we query the API for the timestamp of the
652668 // hash and use that to clone.
653669
654- uri , err := url . Parse (uriString )
670+ uri , err := gitURLParse (uriString )
655671 if err != nil {
656672 return "" , false , fmt .Errorf ("unable to parse Git URI: %s" , err )
657673 }
@@ -715,7 +731,7 @@ func PrepareRepoSinceCommit(uriString, commitHash string) (string, bool, error)
715731// PrepareRepo clones a repo if possible and returns the cloned repo path.
716732func PrepareRepo (uriString string ) (string , bool , error ) {
717733 var path string
718- uri , err := url . Parse (uriString )
734+ uri , err := gitURLParse (uriString )
719735 if err != nil {
720736 return "" , false , fmt .Errorf ("unable to parse Git URI: %s" , err )
721737 }
0 commit comments