summaryrefslogtreecommitdiffstats
path: root/modules/templates/helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/templates/helper.go')
-rw-r--r--modules/templates/helper.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index ef7b70c09f..03e0e9899b 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -32,6 +32,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/emoji"
"code.gitea.io/gitea/modules/git"
+ giturl "code.gitea.io/gitea/modules/git/url"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
@@ -971,20 +972,35 @@ type remoteAddress struct {
Password string
}
-func mirrorRemoteAddress(ctx context.Context, m repo_model.RemoteMirrorer) remoteAddress {
+func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
a := remoteAddress{}
+ if !m.IsMirror {
+ return a
+ }
+
+ remoteURL := m.OriginalURL
+ if remoteURL == "" {
+ var err error
+ remoteURL, err = git.GetRemoteAddress(ctx, m.RepoPath(), remoteName)
+ if err != nil {
+ log.Error("GetRemoteURL %v", err)
+ return a
+ }
+ }
- u, err := git.GetRemoteAddress(ctx, m.GetRepository().RepoPath(), m.GetRemoteName())
+ u, err := giturl.Parse(remoteURL)
if err != nil {
- log.Error("GetRemoteAddress %v", err)
+ log.Error("giturl.Parse %v", err)
return a
}
- if u.User != nil {
- a.Username = u.User.Username()
- a.Password, _ = u.User.Password()
+ if u.Scheme != "ssh" && u.Scheme != "file" {
+ if u.User != nil {
+ a.Username = u.User.Username()
+ a.Password, _ = u.User.Password()
+ }
+ u.User = nil
}
- u.User = nil
a.Address = u.String()
return a