loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix incorrect default branch when adopt a repository (#30912)

Fix #30521

we should sync branches first, then detect default branch, or
`git_model.FindBranchNames` will always return empty list, and the
detection will be wrong.

(cherry picked from commit e94723f2de7d9bf12d870f5ce9ffb291a99ba090)

Conflicts:
services/repository/adopt.go
trivial conflict because
e80466f734 Resolve lint for unused parameter and unnecessary type arguments (#30750)
was not cherry-picked

authored by

yp05327 and committed by
Earl Warren
1a250c7b 6c9b8401

+16 -21
+16 -21
services/repository/adopt.go
··· 36 36 } 37 37 } 38 38 39 - if len(opts.DefaultBranch) == 0 { 40 - opts.DefaultBranch = setting.Repository.DefaultBranch 41 - } 42 - 43 39 repo := &repo_model.Repository{ 44 40 OwnerID: u.ID, 45 41 Owner: u, ··· 81 77 } 82 78 83 79 if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil { 84 - return fmt.Errorf("createDelegateHooks: %w", err) 80 + return fmt.Errorf("adoptRepository: %w", err) 85 81 } 86 82 87 83 if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil { ··· 143 139 } 144 140 } 145 141 142 + // Don't bother looking this repo in the context it won't be there 143 + gitRepo, err := gitrepo.OpenRepository(ctx, repo) 144 + if err != nil { 145 + return fmt.Errorf("openRepository: %w", err) 146 + } 147 + defer gitRepo.Close() 148 + 149 + if _, err = repo_module.SyncRepoBranchesWithRepo(ctx, repo, gitRepo, 0); err != nil { 150 + return fmt.Errorf("SyncRepoBranchesWithRepo: %w", err) 151 + } 152 + 153 + if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil { 154 + return fmt.Errorf("SyncReleasesWithTags: %w", err) 155 + } 156 + 146 157 branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ 147 158 RepoID: repo.ID, 148 159 ListOptions: db.ListOptionsAll, ··· 183 194 return fmt.Errorf("setDefaultBranch: %w", err) 184 195 } 185 196 } 186 - 187 197 if err = repo_module.UpdateRepository(ctx, repo, false); err != nil { 188 198 return fmt.Errorf("updateRepository: %w", err) 189 - } 190 - 191 - // Don't bother looking this repo in the context it won't be there 192 - gitRepo, err := gitrepo.OpenRepository(ctx, repo) 193 - if err != nil { 194 - return fmt.Errorf("openRepository: %w", err) 195 - } 196 - defer gitRepo.Close() 197 - 198 - if _, err = repo_module.SyncRepoBranchesWithRepo(ctx, repo, gitRepo, 0); err != nil { 199 - return fmt.Errorf("SyncRepoBranches: %w", err) 200 - } 201 - 202 - if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil { 203 - return fmt.Errorf("SyncReleasesWithTags: %w", err) 204 199 } 205 200 206 201 return nil