Skip to content

Commit

Permalink
Fixes incorrect URL for submodules that specify the remote port
Browse files Browse the repository at this point in the history
  If the repo's host is in urlPrefix, test if there is a number after the
":" and, if there is one, consider it as a port number and ignore it in the
URL returned.

  Fixes go-gitea/gitea#2775

Signed-off-by: Fernando Governatore <[email protected]>
  • Loading branch information
Fernando Governatore committed Jan 26, 2018
1 parent 6798d0f commit 0ef46ae
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package git

import "strings"
import (
"strings"
"strconv"
)

// SubModule submodule is a reference on git repository
type SubModule struct {
Expand Down Expand Up @@ -58,14 +61,21 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
}

// sysuser@xxx:user/repo
// or
// sysuser@xxx:port/user/repo
i := strings.Index(url, "@")
j := strings.LastIndex(url, ":")

// Only process when i < j because git+ssh://[email protected]/npploader.git
if i > -1 && j > -1 && i < j {
// fix problem with reverse proxy works only with local server
if strings.Contains(urlPrefix, url[i+1:j]) {
return urlPrefix + url[j+1:]
port := strings.Index(url[j+1:], "/")
_, err := strconv.ParseInt(url[j+1:j+1 + port],10,16)
if err != nil {
return urlPrefix + url[j+1:]
}
return urlPrefix + url[j+1 + port+1:]
}
return "http://" + url[i+1:j] + "/" + url[j+1:]
}
Expand Down

0 comments on commit 0ef46ae

Please sign in to comment.