@@ -8,33 +8,32 @@ import "strings"
8
8
9
9
type SubModule struct {
10
10
Name string
11
- Url string
11
+ URL string
12
12
}
13
13
14
14
// SubModuleFile represents a file with submodule type.
15
15
type SubModuleFile struct {
16
16
* Commit
17
17
18
- refUrl string
19
- refId string
18
+ refURL string
19
+ refID string
20
20
}
21
21
22
- func NewSubModuleFile (c * Commit , refUrl , refId string ) * SubModuleFile {
22
+ func NewSubModuleFile (c * Commit , refURL , refID string ) * SubModuleFile {
23
23
return & SubModuleFile {
24
24
Commit : c ,
25
- refUrl : refUrl ,
26
- refId : refId ,
25
+ refURL : refURL ,
26
+ refID : refID ,
27
27
}
28
28
}
29
29
30
- // FIXME: remove import of setting
31
- // RefUrl guesses and returns reference URL.
32
- func (sf * SubModuleFile ) RefUrl (urlPrefix string , parentPath string ) string {
33
- if sf .refUrl == "" {
30
+ // RefURL guesses and returns reference URL.
31
+ func (sf * SubModuleFile ) RefURL (urlPrefix string , parentPath string ) string {
32
+ if sf .refURL == "" {
34
33
return ""
35
34
}
36
35
37
- url := strings .TrimSuffix (sf .refUrl , ".git" )
36
+ url := strings .TrimSuffix (sf .refURL , ".git" )
38
37
39
38
// git://xxx/user/repo
40
39
if strings .HasPrefix (url , "git://" ) {
@@ -46,12 +45,14 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
46
45
return url
47
46
}
48
47
49
- // relative url prefix check (according to git submodule documentation)
48
+ // Relative url prefix check (according to git submodule documentation)
50
49
if strings .HasPrefix (url , "./" ) || strings .HasPrefix (url , "../" ) {
51
50
// ...construct and return correct submodule url here...
52
- idx := strings .LastIndex (parentPath , "/src/" )
53
- rel_url := strings .TrimSuffix (urlPrefix , "/" ) + parentPath [:idx ] + "/" + url
54
- return rel_url
51
+ idx := strings .Index (parentPath , "/src/" )
52
+ if idx == - 1 {
53
+ return url
54
+ }
55
+ return strings .TrimSuffix (urlPrefix , "/" ) + parentPath [:idx ] + "/" + url
55
56
}
56
57
57
58
// sysuser@xxx:user/repo
@@ -71,7 +72,7 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
71
72
return url
72
73
}
73
74
74
- // RefId returns reference ID.
75
- func (sf * SubModuleFile ) RefId () string {
76
- return sf .refId
75
+ // RefID returns reference ID.
76
+ func (sf * SubModuleFile ) RefID () string {
77
+ return sf .refID
77
78
}
0 commit comments