Kaynağa Gözat

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.
pull/30929/head
yp05327 3 hafta önce
ebeveyn
işleme
e94723f2de
No account linked to committer's email address
1 değiştirilmiş dosya ile 16 ekleme ve 21 silme
  1. 16
    21
      services/repository/adopt.go

+ 16
- 21
services/repository/adopt.go Dosyayı Görüntüle

} }
} }


if len(opts.DefaultBranch) == 0 {
opts.DefaultBranch = setting.Repository.DefaultBranch
}

repo := &repo_model.Repository{ repo := &repo_model.Repository{
OwnerID: u.ID, OwnerID: u.ID,
Owner: u, Owner: u,
} }


if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil { if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err)
return fmt.Errorf("adoptRepository: %w", err)
} }


if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil { if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil {
} }
} }


// Don't bother looking this repo in the context it won't be there
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
defer gitRepo.Close()

if _, err = repo_module.SyncRepoBranchesWithRepo(ctx, repo, gitRepo, 0); err != nil {
return fmt.Errorf("SyncRepoBranchesWithRepo: %w", err)
}

if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
return fmt.Errorf("SyncReleasesWithTags: %w", err)
}

branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{
RepoID: repo.ID, RepoID: repo.ID,
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
return fmt.Errorf("setDefaultBranch: %w", err) return fmt.Errorf("setDefaultBranch: %w", err)
} }
} }

if err = repo_module.UpdateRepository(ctx, repo, false); err != nil { if err = repo_module.UpdateRepository(ctx, repo, false); err != nil {
return fmt.Errorf("updateRepository: %w", err) return fmt.Errorf("updateRepository: %w", err)
} }


// Don't bother looking this repo in the context it won't be there
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
defer gitRepo.Close()

if _, err = repo_module.SyncRepoBranchesWithRepo(ctx, repo, gitRepo, 0); err != nil {
return fmt.Errorf("SyncRepoBranches: %w", err)
}

if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
return fmt.Errorf("SyncReleasesWithTags: %w", err)
}

return nil return nil
} }



Loading…
İptal
Kaydet