aboutsummaryrefslogtreecommitdiff
path: root/internal/gitutil/submodule.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gitutil/submodule.go')
-rw-r--r--internal/gitutil/submodule.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/internal/gitutil/submodule.go b/internal/gitutil/submodule.go
index e46f48a1..73e08040 100644
--- a/internal/gitutil/submodule.go
+++ b/internal/gitutil/submodule.go
@@ -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