2014-09-22 17:01:19 -04:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-09-21 22:43:16 -04:00
|
|
|
package git
|
|
|
|
|
2014-09-22 17:01:19 -04:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2014-09-21 22:43:16 -04:00
|
|
|
type SubModule struct {
|
|
|
|
Name string
|
|
|
|
Url string
|
|
|
|
}
|
2014-09-22 17:01:19 -04:00
|
|
|
|
|
|
|
// SubModuleFile represents a file with submodule type.
|
|
|
|
type SubModuleFile struct {
|
|
|
|
*Commit
|
|
|
|
|
|
|
|
refUrl string
|
|
|
|
refId string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile {
|
|
|
|
return &SubModuleFile{
|
|
|
|
Commit: c,
|
|
|
|
refUrl: refUrl,
|
|
|
|
refId: refId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RefUrl guesses and returns reference URL.
|
2015-10-24 16:03:08 -04:00
|
|
|
func (sf *SubModuleFile) RefUrl(appUrl string) string {
|
2015-03-09 23:08:17 -04:00
|
|
|
if sf.refUrl == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2014-09-22 17:01:19 -04:00
|
|
|
url := strings.TrimSuffix(sf.refUrl, ".git")
|
|
|
|
|
|
|
|
// git://xxx/user/repo
|
|
|
|
if strings.HasPrefix(url, "git://") {
|
|
|
|
return "http://" + strings.TrimPrefix(url, "git://")
|
|
|
|
}
|
|
|
|
|
|
|
|
// http[s]://xxx/user/repo
|
|
|
|
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
|
|
|
// sysuser@xxx:user/repo
|
|
|
|
i := strings.Index(url, "@")
|
|
|
|
j := strings.LastIndex(url, ":")
|
|
|
|
if i > -1 && j > -1 {
|
2015-10-24 16:03:08 -04:00
|
|
|
// fix problem with reverse proxy works only with local server
|
|
|
|
if strings.Contains(appUrl,url[i+1:j]) {
|
|
|
|
return appUrl + url[j+1:]
|
|
|
|
} else {
|
|
|
|
return "http://" + url[i+1:j] + "/" + url[j+1:]
|
|
|
|
}
|
2014-09-22 17:01:19 -04:00
|
|
|
}
|
2015-10-24 16:03:08 -04:00
|
|
|
|
2014-09-22 17:01:19 -04:00
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
|
|
|
// RefId returns reference ID.
|
|
|
|
func (sf *SubModuleFile) RefId() string {
|
|
|
|
return sf.refId
|
|
|
|
}
|