mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-15 22:42:43 +00:00
[API] make change repo settings work on empty repos (#15778)
* API: Fix #15602 * Add TEST
This commit is contained in:
parent
272bbb200d
commit
e278614753
3 changed files with 28 additions and 13 deletions
|
@ -578,7 +578,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
|||
repo.IsTemplate = *opts.Template
|
||||
}
|
||||
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
|
||||
var err error
|
||||
ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
|
||||
if err != nil {
|
||||
|
@ -589,13 +589,13 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
|||
}
|
||||
|
||||
// Default branch only updated if changed and exist or the repository is empty
|
||||
if opts.DefaultBranch != nil &&
|
||||
repo.DefaultBranch != *opts.DefaultBranch &&
|
||||
(ctx.Repo.Repository.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
|
||||
if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil {
|
||||
if !git.IsErrUnsupportedVersion(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err)
|
||||
return err
|
||||
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
|
||||
if !repo.IsEmpty {
|
||||
if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil {
|
||||
if !git.IsErrUnsupportedVersion(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
repo.DefaultBranch = *opts.DefaultBranch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue