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.
This commit is contained in:
goriy 2016-06-27 18:19:41 +03:00 коммит произвёл 无闻
Родитель 1f1117c396
Коммит c61be7813a
1 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -29,7 +29,7 @@ func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile {
// FIXME: remove import of setting
// RefUrl guesses and returns reference URL.
func (sf *SubModuleFile) RefUrl(urlPrefix string) string {
func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
if sf.refUrl == "" {
return ""
}
@ -46,6 +46,14 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string) string {
return url
}
// relative url prefix check (according to git submodule documentation)
if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") {
// ...construct and return correct submodule url here...
idx := strings.LastIndex(parentPath, "/src/")
rel_url := strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
return rel_url
}
// sysuser@xxx:user/repo
i := strings.Index(url, "@")
j := strings.LastIndex(url, ":")