Skip to content

Commit 35ce7ca

Browse files
n0toosesilverwindGiteaBot
authored
Hide 'Mirror Settings' when unneeded, improve hints (#24433)
Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
1 parent a70d853 commit 35ce7ca

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

options/locale/locale_en-US.ini

+10-1
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,16 @@ settings.hooks = Webhooks
19131913
settings.githooks = Git Hooks
19141914
settings.basic_settings = Basic Settings
19151915
settings.mirror_settings = Mirror Settings
1916-
settings.mirror_settings.docs = Set up your project to automatically push and/or pull changes to/from another repository. Branches, tags, and commits will be synced automatically. <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/repo-mirror/">How do I mirror repositories?</a>
1916+
settings.mirror_settings.docs = Set up your repository to automatically synchronize commits, tags and branches with another repository.
1917+
settings.mirror_settings.docs.disabled_pull_mirror.instructions = Set up your project to automatically push commits, tags and branches to another repository. Pull mirrors have been disabled by your site administrator.
1918+
settings.mirror_settings.docs.disabled_push_mirror.instructions = Set up your project to automatically pull commits, tags and branches from another repository.
1919+
settings.mirror_settings.docs.disabled_push_mirror.pull_mirror_warning = Right now, this can only be done in the "New Migration" menu. For more information, please consult:
1920+
settings.mirror_settings.docs.disabled_push_mirror.info = Push mirrors have been disabled by your site administrator.
1921+
settings.mirror_settings.docs.no_new_mirrors = Your repository is mirroring changes to or from another repository. Please keep in mind that you can't create any new mirrors at this time.
1922+
settings.mirror_settings.docs.can_still_use = Although you can't modify existing mirrors or create new ones, you may still use your existing mirror.
1923+
settings.mirror_settings.docs.pull_mirror_instructions = To set up a pull mirror, please consult:
1924+
settings.mirror_settings.docs.doc_link_title = How do I mirror repositories?
1925+
settings.mirror_settings.docs.pulling_remote_title = Pulling from a remote repository
19171926
settings.mirror_settings.mirrored_repository = Mirrored repository
19181927
settings.mirror_settings.direction = Direction
19191928
settings.mirror_settings.direction.pull = Pull

routers/web/repo/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func SettingsCtxData(ctx *context.Context) {
6464
ctx.Data["PageIsSettingsOptions"] = true
6565
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
6666
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
67+
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
6768
ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush
6869
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
6970
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
@@ -108,6 +109,7 @@ func SettingsPost(ctx *context.Context) {
108109

109110
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
110111
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
112+
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
111113
ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush
112114
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
113115
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval

templates/repo/settings/options.tmpl

+35-5
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,44 @@
6767

6868
</div>
6969

70-
{{if .MirrorsEnabled}}
70+
71+
{{/* These variables exist to make the logic in the Settings window easier to comprehend and are not used later on. */}}
72+
{{$newMirrorsPartiallyEnabled := or (not .DisableNewPullMirrors) (not .DisableNewPushMirrors)}}
73+
{{/* .Repository.IsMirror is not always reliable if the repository is not actively acting as a mirror because of errors. */}}
74+
{{$showMirrorSettings := or $newMirrorsPartiallyEnabled .Repository.IsMirror .PullMirror .PushMirrors}}
75+
{{$newMirrorsEntirelyEnabled := and (not .DisableNewPullMirrors) (not .DisableNewPushMirrors)}}
76+
{{$onlyNewPushMirrorsEnabled := and (not .DisableNewPushMirrors) .DisableNewPullMirrors}}
77+
{{$onlyNewPullMirrorsEnabled := and .DisableNewPushMirrors (not .DisableNewPullMirrors)}}
78+
{{$existingPushMirror := or .Repository.IsMirror .PushMirrors}}
79+
{{$modifyBrokenPullMirror := and .Repository.IsMirror (not .PullMirror)}}
80+
{{$isWorkingPullMirror := .PullMirror}}
81+
82+
{{if $showMirrorSettings}}
7183
<h4 class="ui top attached header">
7284
{{.locale.Tr "repo.settings.mirror_settings"}}
7385
</h4>
7486
<div class="ui attached segment">
75-
{{$.locale.Tr "repo.settings.mirror_settings.docs" | Safe}}
87+
{{if $newMirrorsEntirelyEnabled}}
88+
{{$.locale.Tr "repo.settings.mirror_settings.docs"}}
89+
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pushing-to<ing-to-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
90+
{{$.locale.Tr "repo.settings.mirror_settings.docs.pull_mirror_instructions"}}
91+
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br>
92+
{{else if $onlyNewPushMirrorsEnabled}}
93+
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_pull_mirror.instructions"}}
94+
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br>
95+
{{else if $onlyNewPullMirrorsEnabled}}
96+
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.instructions"}}
97+
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.pull_mirror_warning"}}
98+
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
99+
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.info"}}
100+
{{if $existingPushMirror}}
101+
{{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_use"}}
102+
{{end}}
103+
{{else}}
104+
{{$.locale.Tr "repo.settings.mirror_settings.docs.no_new_mirrors"}} {{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_use"}}<br>
105+
{{end}}
76106
<table class="ui table">
77-
{{if or .Repository.IsMirror .PushMirrors}}
107+
{{if $existingPushMirror}}
78108
<thead>
79109
<tr>
80110
<th style="width:40%">{{$.locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}</th>
@@ -84,7 +114,7 @@
84114
</tr>
85115
</thead>
86116
{{end}}
87-
{{if and .Repository.IsMirror (not .PullMirror)}}
117+
{{if $modifyBrokenPullMirror}}
88118
{{/* even if a repo is a pull mirror (IsMirror=true), the PullMirror might still be nil if the mirror migration is broken */}}
89119
<tbody>
90120
<tr>
@@ -93,7 +123,7 @@
93123
</td>
94124
</tr>
95125
</tbody>
96-
{{else if .PullMirror}}
126+
{{else if $isWorkingPullMirror}}
97127
<tbody>
98128
<tr>
99129
<td>{{(MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false).Address}}</td>

0 commit comments

Comments
 (0)