mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
8 years ago
|
// Copyright 2015 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.
|
||
|
|
||
|
package git
|
||
|
|
||
|
import "strings"
|
||
|
|
||
8 years ago
|
// SubModule submodule is a reference on git repository
|
||
8 years ago
|
type SubModule struct {
|
||
|
Name string
|
||
|
URL string
|
||
|
}
|
||
|
|
||
|
// SubModuleFile represents a file with submodule type.
|
||
|
type SubModuleFile struct {
|
||
|
*Commit
|
||
|
|
||
|
refURL string
|
||
|
refID string
|
||
|
}
|
||
|
|
||
8 years ago
|
// NewSubModuleFile create a new submodule file
|
||
8 years ago
|
func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
|
||
|
return &SubModuleFile{
|
||
|
Commit: c,
|
||
|
refURL: refURL,
|
||
|
refID: refID,
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
func getRefURL(refURL, urlPrefix, parentPath string) string {
|
||
|
if refURL == "" {
|
||
8 years ago
|
return ""
|
||
|
}
|
||
|
|
||
6 years ago
|
url := strings.TrimSuffix(refURL, ".git")
|
||
8 years ago
|
|
||
|
// 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
|
||
|
}
|
||
|
|
||
|
// 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.Index(parentPath, "/src/")
|
||
|
if idx == -1 {
|
||
|
return url
|
||
|
}
|
||
|
return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
|
||
|
}
|
||
|
|
||
|
// sysuser@xxx:user/repo
|
||
|
i := strings.Index(url, "@")
|
||
|
j := strings.LastIndex(url, ":")
|
||
|
|
||
|
// Only process when i < j because git+ssh://git@git.forwardbias.in/npploader.git
|
||
|
if i > -1 && j > -1 && i < j {
|
||
|
// fix problem with reverse proxy works only with local server
|
||
|
if strings.Contains(urlPrefix, url[i+1:j]) {
|
||
|
return urlPrefix + url[j+1:]
|
||
|
}
|
||
6 years ago
|
if strings.HasPrefix(url, "ssh://") || strings.HasPrefix(url, "git+ssh://") {
|
||
|
k := strings.Index(url[j+1:], "/")
|
||
|
return "http://" + url[i+1:j] + "/" + url[j+1:][k+1:]
|
||
|
}
|
||
8 years ago
|
return "http://" + url[i+1:j] + "/" + url[j+1:]
|
||
8 years ago
|
}
|
||
|
|
||
|
return url
|
||
|
}
|
||
|
|
||
6 years ago
|
// RefURL guesses and returns reference URL.
|
||
|
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
|
||
|
return getRefURL(sf.refURL, urlPrefix, parentPath)
|
||
|
}
|
||
|
|
||
8 years ago
|
// RefID returns reference ID.
|
||
|
func (sf *SubModuleFile) RefID() string {
|
||
|
return sf.refID
|
||
|
}
|