Skip to content

Commit c61be78

Browse files
goriyunknwon
authored andcommitted
Fixed incorrect creation of relative submodule URL (#14)
According to git submodule documentation base path for relative submodule URL is parent repository's root - not submodule "mount point". So it's necessary to know "path" of parent repository to create correct submodule URL.
1 parent 1f1117c commit c61be78

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

submodule.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile {
2929

3030
// FIXME: remove import of setting
3131
// RefUrl guesses and returns reference URL.
32-
func (sf *SubModuleFile) RefUrl(urlPrefix string) string {
32+
func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
3333
if sf.refUrl == "" {
3434
return ""
3535
}
@@ -46,6 +46,14 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string) string {
4646
return url
4747
}
4848

49+
// relative url prefix check (according to git submodule documentation)
50+
if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") {
51+
// ...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
55+
}
56+
4957
// sysuser@xxx:user/repo
5058
i := strings.Index(url, "@")
5159
j := strings.LastIndex(url, ":")

0 commit comments

Comments
 (0)