From efaa9958b5a5b90381da439ba78a0abad945703e Mon Sep 17 00:00:00 2001 From: xpy <865934097@qq.com> Date: Mon, 15 Aug 2022 11:12:01 +0800 Subject: [PATCH] Fix push mirror address backend get error Address cause setting page display error (#20593) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao --- modules/templates/helper.go | 4 ++-- templates/repo/header.tmpl | 2 +- templates/repo/settings/options.tmpl | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 8a15cec2c..602afec41 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -972,11 +972,11 @@ type remoteAddress struct { Password string } -func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress { +func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string, ignoreOriginalURL bool) remoteAddress { a := remoteAddress{} remoteURL := m.OriginalURL - if remoteURL == "" { + if ignoreOriginalURL || remoteURL == "" { var err error remoteURL, err = git.GetRemoteAddress(ctx, m.RepoPath(), remoteName) if err != nil { diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 87a4a2fda..e6ed76bb6 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -38,7 +38,7 @@ {{if $.IsPullMirror}} - {{$address := MirrorRemoteAddress $.Context . $.Mirror.GetRemoteName}} + {{$address := MirrorRemoteAddress $.Context . $.Mirror.GetRemoteName false}}
{{$.locale.Tr "repo.mirror_from"}} {{$address.Address}}
{{end}} {{if .IsFork}}
{{$.locale.Tr "repo.forked_from"}} {{.BaseRepo.FullName}}
{{end}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 98cf4f88c..f34057d9c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -91,7 +91,7 @@ {{if .Repository.IsMirror}} - {{(MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName).Address}} + {{(MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false).Address}} {{$.locale.Tr "repo.settings.mirror_settings.direction.pull"}} {{.Mirror.UpdatedUnix.AsTime}} @@ -119,7 +119,7 @@ - {{$address := MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName}} + {{$address := MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false}}
@@ -168,7 +168,7 @@ {{range .PushMirrors}} - {{$address := MirrorRemoteAddress $.Context $.Repository .GetRemoteName}} + {{$address := MirrorRemoteAddress $.Context $.Repository .GetRemoteName true}} {{$address.Address}} {{$.locale.Tr "repo.settings.mirror_settings.direction.push"}} {{if .LastUpdateUnix}}{{.LastUpdateUnix.AsTime}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}
{{$.locale.Tr "error"}}
{{end}}