mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 07:09:58 +01:00
gitutil: infer submodule with baseURL when it is a relative path (#6337)
This commit is contained in:
@@ -17,10 +17,21 @@ import (
|
||||
var scpSyntax = lazyregexp.New(`^([a-zA-Z0-9_]+@)?([a-zA-Z0-9._-]+):(.*)$`)
|
||||
|
||||
// InferSubmoduleURL returns the inferred external URL of the submodule at best effort.
|
||||
func InferSubmoduleURL(mod *git.Submodule) string {
|
||||
// The `baseURL` should be the URL of the current repository. If the submodule URL looks
|
||||
// like a relative path, it assumes that the submodule is another repository on the same
|
||||
// Gogs instance by appending it to the `baseURL` with the commit.
|
||||
func InferSubmoduleURL(baseURL string, mod *git.Submodule) string {
|
||||
if !strings.HasSuffix(baseURL, "/") {
|
||||
baseURL += "/"
|
||||
}
|
||||
|
||||
raw := strings.TrimSuffix(mod.URL, "/")
|
||||
raw = strings.TrimSuffix(raw, ".git")
|
||||
|
||||
if strings.HasPrefix(raw, "../") {
|
||||
return fmt.Sprintf("%s%s/commit/%s", baseURL, raw, mod.Commit)
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
// Try parse as SCP syntax again
|
||||
|
||||
Reference in New Issue
Block a user