mirror of
https://github.com/go-gitea/git.git
synced 2026-02-05 06:45:03 +01:00
fix submodule has port (#136)
This commit is contained in:
16
submodule.go
16
submodule.go
@@ -29,13 +29,12 @@ func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
|
||||
}
|
||||
}
|
||||
|
||||
// RefURL guesses and returns reference URL.
|
||||
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
|
||||
if sf.refURL == "" {
|
||||
func getRefURL(refURL, urlPrefix, parentPath string) string {
|
||||
if refURL == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
url := strings.TrimSuffix(sf.refURL, ".git")
|
||||
url := strings.TrimSuffix(refURL, ".git")
|
||||
|
||||
// git://xxx/user/repo
|
||||
if strings.HasPrefix(url, "git://") {
|
||||
@@ -67,12 +66,21 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
|
||||
if strings.Contains(urlPrefix, url[i+1:j]) {
|
||||
return urlPrefix + url[j+1:]
|
||||
}
|
||||
if strings.HasPrefix(url, "ssh://") || strings.HasPrefix(url, "git+ssh://") {
|
||||
k := strings.Index(url[j+1:], "/")
|
||||
return "http://" + url[i+1:j] + "/" + url[j+1:][k+1:]
|
||||
}
|
||||
return "http://" + url[i+1:j] + "/" + url[j+1:]
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
// RefURL guesses and returns reference URL.
|
||||
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
|
||||
return getRefURL(sf.refURL, urlPrefix, parentPath)
|
||||
}
|
||||
|
||||
// RefID returns reference ID.
|
||||
func (sf *SubModuleFile) RefID() string {
|
||||
return sf.refID
|
||||
|
||||
29
submodule_test.go
Normal file
29
submodule_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetRefURL(t *testing.T) {
|
||||
var kases = []struct {
|
||||
refURL string
|
||||
prefixURL string
|
||||
parentPath string
|
||||
expect string
|
||||
}{
|
||||
{"git://github.com/user1/repo1", "/", "/", "http://github.com/user1/repo1"},
|
||||
{"https://localhost/user1/repo1.git", "/", "/", "https://localhost/user1/repo1"},
|
||||
{"git@github.com/user1/repo1.git", "/", "/", "git@github.com/user1/repo1"},
|
||||
{"ssh://git@git.zefie.net:2222/zefie/lge_g6_kernel_scripts.git", "/", "/", "http://git.zefie.net/zefie/lge_g6_kernel_scripts"},
|
||||
}
|
||||
|
||||
for _, kase := range kases {
|
||||
assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user