From eb4fc987feec67bf59e9eefa9f26a7e17308f51e Mon Sep 17 00:00:00 2001 From: Job Date: Mon, 19 Aug 2024 18:40:10 +0000 Subject: [PATCH] Fixed if statement to correctly check base repository --- routers/api/v1/repo/pull.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 8ba6c096ece8e..ebde9ea8a9099 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1110,18 +1110,20 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if current user has fork of repository or in the same repository. headRepo := repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) if headRepo == nil && !isSameRepo { - // Check if the base repository is a fork of the head repository. - headRepo, err = repo_model.GetRepositoryByID(ctx, baseRepo.ForkID) + err := baseRepo.GetBaseRepo(ctx) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) + ctx.Error(http.StatusInternalServerError, "GetBaseRepo", err) return nil, nil, nil, "", "" } - if headRepo == nil { + // Check if baseRepo's base repository is the same as headUser's repository. + if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != headUser.ID { log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.NotFound("GetForkedRepo") + ctx.NotFound("GetBaseRepo") return nil, nil, nil, "", "" } + // Assign headRepo so it can be used below. + headRepo = baseRepo.BaseRepo } var headGitRepo *git.Repository