Skip to content

Commit 7f046e5

Browse files
committed
fix
1 parent 9897baf commit 7f046e5

File tree

6 files changed

+45
-33
lines changed

6 files changed

+45
-33
lines changed

models/repo/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ type Repository struct {
149149
IsEmpty bool `xorm:"INDEX"`
150150
IsArchived bool `xorm:"INDEX"`
151151
IsMirror bool `xorm:"INDEX"`
152-
*Mirror `xorm:"-"`
153-
Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
152+
153+
Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
154154

155155
RenderingMetas map[string]string `xorm:"-"`
156156
DocumentRenderingMetas map[string]string `xorm:"-"`

modules/context/repo.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type Repository struct {
6161
RepoLink string
6262
CloneLink repo_model.CloneLink
6363
CommitsCount int64
64-
Mirror *repo_model.Mirror
6564

6665
PullRequest *PullRequest
6766
}
@@ -380,13 +379,9 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
380379
ctx.Data["Permission"] = &ctx.Repo.Permission
381380

382381
if repo.IsMirror {
383-
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(ctx, repo.ID)
382+
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
384383
if err == nil {
385-
ctx.Repo.Mirror.Repo = repo
386-
ctx.Data["IsPullMirror"] = true
387-
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
388-
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
389-
ctx.Data["Mirror"] = ctx.Repo.Mirror
384+
ctx.Data["PullMirror"] = pullMirror
390385
} else if err != repo_model.ErrMirrorNotExist {
391386
ctx.ServerError("GetMirrorByRepoID", err)
392387
return

routers/web/repo/setting.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ func SettingsPost(ctx *context.Context) {
198198
return
199199
}
200200

201+
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, ctx.Repo.Repository.ID)
202+
if err == repo_model.ErrMirrorNotExist {
203+
ctx.NotFound("", nil)
204+
return
205+
}
206+
if err != nil {
207+
ctx.ServerError("GetMirrorByRepoID", err)
208+
return
209+
}
201210
// This section doesn't require repo_name/RepoName to be set in the form, don't show it
202211
// as an error on the UI for this action
203212
ctx.Data["Err_RepoName"] = nil
@@ -209,15 +218,15 @@ func SettingsPost(ctx *context.Context) {
209218
return
210219
}
211220

212-
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
213-
ctx.Repo.Mirror.Interval = interval
214-
ctx.Repo.Mirror.ScheduleNextUpdate()
215-
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
221+
pullMirror.EnablePrune = form.EnablePrune
222+
pullMirror.Interval = interval
223+
pullMirror.ScheduleNextUpdate()
224+
if err := repo_model.UpdateMirror(ctx, pullMirror); err != nil {
216225
ctx.ServerError("UpdateMirror", err)
217226
return
218227
}
219228

220-
u, err := git.GetRemoteURL(ctx, ctx.Repo.Repository.RepoPath(), ctx.Repo.Mirror.GetRemoteName())
229+
u, err := git.GetRemoteURL(ctx, ctx.Repo.Repository.RepoPath(), pullMirror.GetRemoteName())
221230
if err != nil {
222231
ctx.Data["Err_MirrorAddress"] = true
223232
handleSettingRemoteAddrError(ctx, err, form)
@@ -237,7 +246,7 @@ func SettingsPost(ctx *context.Context) {
237246
return
238247
}
239248

240-
if err := mirror_service.UpdateAddress(ctx, ctx.Repo.Mirror, address); err != nil {
249+
if err := mirror_service.UpdateAddress(ctx, pullMirror, address); err != nil {
241250
ctx.ServerError("UpdateAddress", err)
242251
return
243252
}
@@ -259,9 +268,9 @@ func SettingsPost(ctx *context.Context) {
259268
}
260269
}
261270

262-
ctx.Repo.Mirror.LFS = form.LFS
263-
ctx.Repo.Mirror.LFSEndpoint = form.LFSEndpoint
264-
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
271+
pullMirror.LFS = form.LFS
272+
pullMirror.LFSEndpoint = form.LFSEndpoint
273+
if err := repo_model.UpdateMirror(ctx, pullMirror); err != nil {
265274
ctx.ServerError("UpdateMirror", err)
266275
return
267276
}

services/convert/repository.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
124124
mirrorInterval := ""
125125
var mirrorUpdated time.Time
126126
if repo.IsMirror {
127-
var err error
128-
repo.Mirror, err = repo_model.GetMirrorByRepoID(ctx, repo.ID)
127+
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
129128
if err == nil {
130-
mirrorInterval = repo.Mirror.Interval.String()
131-
mirrorUpdated = repo.Mirror.UpdatedUnix.AsTime()
129+
mirrorInterval = pullMirror.Interval.String()
130+
mirrorUpdated = pullMirror.UpdatedUnix.AsTime()
132131
}
133132
}
134133

templates/repo/header.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<a class="rss-icon gt-ml-3" href="{{$.RepoLink}}.rss" data-tooltip-content="{{$.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 18}}</a>
4040
{{end}}
4141
</div>
42-
{{if $.IsPullMirror}}
43-
{{$address := MirrorRemoteAddress $.Context . $.Mirror.GetRemoteName false}}
42+
{{if $.PullMirror}}
43+
{{$address := MirrorRemoteAddress $.Context . $.PullMirror.GetRemoteName false}}
4444
<div class="fork-flag">{{$.locale.Tr "repo.mirror_from"}} <a target="_blank" rel="noopener noreferrer" href="{{$address.Address}}">{{$address.Address}}</a></div>
4545
{{end}}
4646
{{if .IsFork}}<div class="fork-flag">{{$.locale.Tr "repo.forked_from"}} <a href="{{.BaseRepo.Link}}">{{.BaseRepo.FullName}}</a></div>{{end}}

templates/repo/settings/options.tmpl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,21 @@
8484
</tr>
8585
</thead>
8686
{{end}}
87-
{{if .Repository.IsMirror}}
87+
{{if and .Repository.IsMirror (not .PullMirror)}}
88+
{{/* even if a repo is a pull mirror (IsMirror=true), the PullMirror might still be nil if the mirror migration is broken */}}
89+
<tbody>
90+
<tr>
91+
<td colspan="4">
92+
<span class="text red gt-db gt-py-4 gt-border-secondary-bottom">{{$.locale.Tr "repo.settings.mirror_settings.direction.pull"}}: {{$.locale.Tr "error.occurred"}}</span>
93+
</td>
94+
</tr>
95+
</tbody>
96+
{{else if .PullMirror}}
8897
<tbody>
8998
<tr>
90-
<td>{{(MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false).Address}}</td>
99+
<td>{{(MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false).Address}}</td>
91100
<td>{{$.locale.Tr "repo.settings.mirror_settings.direction.pull"}}</td>
92-
<td>{{DateTime "full" .Mirror.UpdatedUnix}}</td>
101+
<td>{{DateTime "full" .PullMirror.UpdatedUnix}}</td>
93102
<td class="right aligned">
94103
<form method="post" class="gt-dib">
95104
{{.CsrfTokenHtml}}
@@ -107,15 +116,15 @@
107116
<div class="inline field {{if .Err_EnablePrune}}error{{end}}">
108117
<label>{{.locale.Tr "repo.mirror_prune"}}</label>
109118
<div class="ui checkbox">
110-
<input id="enable_prune" name="enable_prune" type="checkbox" {{if .MirrorEnablePrune}}checked{{end}}>
119+
<input id="enable_prune" name="enable_prune" type="checkbox" {{if .PullMirror.EnablePrune}}checked{{end}}>
111120
<label>{{.locale.Tr "repo.mirror_prune_desc"}}</label>
112121
</div>
113122
</div>
114123
<div class="inline field {{if .Err_Interval}}error{{end}}">
115124
<label for="interval">{{.locale.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
116-
<input id="interval" name="interval" value="{{.MirrorInterval}}">
125+
<input id="interval" name="interval" value="{{.PullMirror.Interval}}">
117126
</div>
118-
{{$address := MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false}}
127+
{{$address := MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false}}
119128
<div class="field {{if .Err_MirrorAddress}}error{{end}}">
120129
<label for="mirror_address">{{.locale.Tr "repo.mirror_address"}}</label>
121130
<input id="mirror_address" name="mirror_address" value="{{$address.Address}}" required>
@@ -142,13 +151,13 @@
142151
<div class="inline field">
143152
<label>{{.locale.Tr "repo.mirror_lfs"}}</label>
144153
<div class="ui checkbox">
145-
<input id="mirror_lfs" name="mirror_lfs" type="checkbox" {{if .Mirror.LFS}}checked{{end}}>
154+
<input id="mirror_lfs" name="mirror_lfs" type="checkbox" {{if .PullMirror.LFS}}checked{{end}}>
146155
<label>{{.locale.Tr "repo.mirror_lfs_desc"}}</label>
147156
</div>
148157
</div>
149158
<div class="field {{if .Err_LFSEndpoint}}error{{end}}">
150159
<label for="mirror_lfs_endpoint">{{.locale.Tr "repo.mirror_lfs_endpoint"}}</label>
151-
<input id="mirror_lfs_endpoint" name="mirror_lfs_endpoint" value="{{.Mirror.LFSEndpoint}}" placeholder="{{.locale.Tr "repo.migrate_options_lfs_endpoint.placeholder"}}">
160+
<input id="mirror_lfs_endpoint" name="mirror_lfs_endpoint" value="{{.PullMirror.LFSEndpoint}}" placeholder="{{.locale.Tr "repo.migrate_options_lfs_endpoint.placeholder"}}">
152161
<p class="help">{{.locale.Tr "repo.mirror_lfs_endpoint_desc" "https://github.com/git-lfs/git-lfs/blob/main/docs/api/server-discovery.md#server-discovery" | Str2html}}</p>
153162
</div>
154163
{{end}}
@@ -160,7 +169,7 @@
160169
</tr>
161170
</tbody>
162171
<thead><tr><th colspan="4"></th></tr></thead>
163-
{{end}}
172+
{{end}}{{/* end if: IsMirror */}}
164173
<tbody>
165174
{{range .PushMirrors}}
166175
<tr>

0 commit comments

Comments
 (0)