diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-06-11 21:50:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-11 21:50:14 +0800 |
commit | ce3dd04c63a048fe791ed864c2023fd37b09e427 (patch) | |
tree | 43ed415dc8d5647b59bf54fddceb4d4a63bcc456 /modules/templates | |
parent | 88f2e457d891c4e91a9eddab8143d0109e08dfa9 (diff) | |
download | gitea-ce3dd04c63a048fe791ed864c2023fd37b09e427.tar.gz gitea-ce3dd04c63a048fe791ed864c2023fd37b09e427.zip |
Fix some mirror bugs (#18649)
* Fix some mirror bugs
* Remove unnecessary code
* Fix lint
* rename stdard url
* Allow more charactors in git ssh protocol url
* improve the detection
* support ipv6 for git url parse
* Fix bug
* Fix template
* Fix bug
* fix template
* Fix tmpl
* Fix tmpl
* Fix parse ssh with interface
* Rename functions name
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 30 |
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 |