123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package git
- import "strings"
- type SubModule struct {
- Name string
- URL string
- }
- type SubModuleFile struct {
- *Commit
- refURL string
- refID string
- }
- func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
- return &SubModuleFile{
- Commit: c,
- refURL: refURL,
- refID: refID,
- }
- }
- func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
- if sf.refURL == "" {
- return ""
- }
- url := strings.TrimSuffix(sf.refURL, ".git")
-
- if strings.HasPrefix(url, "git://") {
- return "http://" + strings.TrimPrefix(url, "git://")
- }
-
- if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
- return url
- }
-
- if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") {
-
- idx := strings.Index(parentPath, "/src/")
- if idx == -1 {
- return url
- }
- return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
- }
-
- i := strings.Index(url, "@")
- j := strings.LastIndex(url, ":")
-
- if i > -1 && j > -1 && i < j {
-
- if strings.Contains(urlPrefix, url[i+1:j]) {
- return urlPrefix + url[j+1:]
- } else {
- return "http://" + url[i+1:j] + "/" + url[j+1:]
- }
- }
- return url
- }
- func (sf *SubModuleFile) RefID() string {
- return sf.refID
- }
|