forked from go-gitea/git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes incorrect url for submodules that specify the remote port
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 5c8129c
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
|
||
package git | ||
|
||
import "strings" | ||
import ( | ||
"strings" | ||
"strconv" | ||
) | ||
|
||
// SubModule submodule is a reference on git repository | ||
type SubModule struct { | ||
|
@@ -58,14 +61,22 @@ 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:] | ||
} else { | ||
return urlPrefix + url[j+1 + port+1:] | ||
} | ||
} | ||
return "http://" + url[i+1:j] + "/" + url[j+1:] | ||
} | ||
|