1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Fix bug when migrating repository (#34182)

This PR fixed a bug which is a regression from #31035
This commit is contained in:
Lunny Xiao
2025-04-13 21:48:03 -07:00
committed by GitHub
parent 8a6df00c53
commit f6474cf2e9
12 changed files with 19 additions and 17 deletions

View File

@@ -199,7 +199,10 @@ func initRepository(ctx context.Context, u *user_model.User, repo *repo_model.Re
}
// CreateRepositoryDirectly creates a repository for the user/organization.
func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error) {
// if needsUpdateToReady is true, it will update the repository status to ready when success
func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
opts CreateRepoOptions, needsUpdateToReady bool,
) (*repo_model.Repository, error) {
if !doer.CanCreateRepoIn(owner) {
return nil, repo_model.ErrReachLimitOfRepo{
Limit: owner.MaxRepoCreation,
@@ -243,8 +246,6 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
ObjectFormatName: opts.ObjectFormatName,
}
needsUpdateStatus := opts.Status != repo_model.RepositoryReady
// 1 - create the repository database operations first
err := db.WithTx(ctx, func(ctx context.Context) error {
return createRepositoryInDB(ctx, doer, owner, repo, false)
@@ -318,7 +319,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
}
// 7 - update repository status to be ready
if needsUpdateStatus {
if needsUpdateToReady {
repo.Status = repo_model.RepositoryReady
if err = repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
return nil, fmt.Errorf("UpdateRepositoryCols: %w", err)

View File

@@ -25,7 +25,7 @@ func TestCreateRepositoryDirectly(t *testing.T) {
createdRepo, err := CreateRepositoryDirectly(git.DefaultContext, user2, user2, CreateRepoOptions{
Name: "created-repo",
})
}, true)
assert.NoError(t, err)
assert.NotNil(t, createdRepo)
@@ -44,7 +44,7 @@ func TestCreateRepositoryDirectly(t *testing.T) {
createdRepo2, err := CreateRepositoryDirectly(db.DefaultContext, user2, user2, CreateRepoOptions{
Name: "created-repo",
})
}, true)
assert.Nil(t, createdRepo2)
assert.Error(t, err)

View File

@@ -47,7 +47,7 @@ type WebSearchResults struct {
// CreateRepository creates a repository for the user/organization.
func CreateRepository(ctx context.Context, doer, owner *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error) {
repo, err := CreateRepositoryDirectly(ctx, doer, owner, opts)
repo, err := CreateRepositoryDirectly(ctx, doer, owner, opts, true)
if err != nil {
// No need to rollback here we should do this in CreateRepository...
return nil, err