Skip to content

Commit e32ab42

Browse files
Prevent NPE on update mirror settings (#19864)
A `repo_model.Mirror` repository field (`.Repo`) will not automatically be set, but is used without checking in mirror_pull.go:UpdateAddress. This will cause an NPE. This PR changes UpdateAddress to use the helper function GetRepository() helping prevent future NPEs but also changes modules/context/repo.go to ensure that the Mirror.Repo is set. Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 6171ea7 commit e32ab42

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

modules/context/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
391391
ctx.ServerError("GetMirrorByRepoID", err)
392392
return
393393
}
394-
ctx.Repo.Mirror.Repo = ctx.Repo.Repository
394+
ctx.Repo.Mirror.Repo = repo
395395
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
396396
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
397397
ctx.Data["Mirror"] = ctx.Repo.Mirror

services/mirror/mirror_pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const gitShortEmptySha = "0000000"
3232
// UpdateAddress writes new address to Git repository and database
3333
func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error {
3434
remoteName := m.GetRemoteName()
35-
repoPath := m.Repo.RepoPath()
35+
repoPath := m.GetRepository().RepoPath()
3636
// Remove old remote
3737
_, _, err := git.NewCommand(ctx, "remote", "rm", remoteName).RunStdString(&git.RunOpts{Dir: repoPath})
3838
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {

0 commit comments

Comments
 (0)