Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 49292ad

Browse files
lunnylafriks
authored andcommitted
fix submodule has port (#136)
1 parent 7d7fe9f commit 49292ad

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

submodule.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
2929
}
3030
}
3131

32-
// RefURL guesses and returns reference URL.
33-
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
34-
if sf.refURL == "" {
32+
func getRefURL(refURL, urlPrefix, parentPath string) string {
33+
if refURL == "" {
3534
return ""
3635
}
3736

38-
url := strings.TrimSuffix(sf.refURL, ".git")
37+
url := strings.TrimSuffix(refURL, ".git")
3938

4039
// git://xxx/user/repo
4140
if strings.HasPrefix(url, "git://") {
@@ -67,12 +66,21 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
6766
if strings.Contains(urlPrefix, url[i+1:j]) {
6867
return urlPrefix + url[j+1:]
6968
}
69+
if strings.HasPrefix(url, "ssh://") || strings.HasPrefix(url, "git+ssh://") {
70+
k := strings.Index(url[j+1:], "/")
71+
return "http://" + url[i+1:j] + "/" + url[j+1:][k+1:]
72+
}
7073
return "http://" + url[i+1:j] + "/" + url[j+1:]
7174
}
7275

7376
return url
7477
}
7578

79+
// RefURL guesses and returns reference URL.
80+
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
81+
return getRefURL(sf.refURL, urlPrefix, parentPath)
82+
}
83+
7684
// RefID returns reference ID.
7785
func (sf *SubModuleFile) RefID() string {
7886
return sf.refID

submodule_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestGetRefURL(t *testing.T) {
14+
var kases = []struct {
15+
refURL string
16+
prefixURL string
17+
parentPath string
18+
expect string
19+
}{
20+
{"git://github.com/user1/repo1", "/", "/", "http://github.com/user1/repo1"},
21+
{"https://localhost/user1/repo1.git", "/", "/", "https://localhost/user1/repo1"},
22+
{"git@github.com/user1/repo1.git", "/", "/", "git@github.com/user1/repo1"},
23+
{"ssh://git@git.zefie.net:2222/zefie/lge_g6_kernel_scripts.git", "/", "/", "http://git.zefie.net/zefie/lge_g6_kernel_scripts"},
24+
}
25+
26+
for _, kase := range kases {
27+
assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath))
28+
}
29+
}

0 commit comments

Comments
 (0)