diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 54d8f23710..a90dba12c0 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1099,22 +1099,28 @@ func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *par } } if compareReq.HeadRepoName == "" { - headRepo = repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) - if headRepo == nil && headUser.ID != baseRepo.OwnerID { - err = baseRepo.GetBaseRepo(ctx) - if err != nil { - ctx.APIErrorInternal(err) - return nil, nil - } + if headUser.ID == baseRepo.OwnerID { + headRepo = baseRepo + } else { + // TODO: forked's fork + headRepo = repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) + if headRepo == nil { + // TODO: based's base? + err = baseRepo.GetBaseRepo(ctx) + if err != nil { + ctx.APIErrorInternal(err) + return nil, 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.APIErrorNotFound("GetBaseRepo") - return nil, 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.APIErrorNotFound("GetBaseRepo") + return nil, nil + } + // Assign headRepo so it can be used below. + headRepo = baseRepo.BaseRepo } - // Assign headRepo so it can be used below. - headRepo = baseRepo.BaseRepo } } else { if compareReq.HeadOwner == ctx.Repo.Owner.Name && compareReq.HeadRepoName == ctx.Repo.Repository.Name { diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 3340a8d7ab..b325b030a4 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -226,22 +226,28 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } } if compareReq.HeadRepoName == "" { - ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ID) - if ci.HeadRepo == nil && ci.HeadUser.ID != baseRepo.OwnerID { - err = baseRepo.GetBaseRepo(ctx) - if err != nil { - ctx.ServerError("GetBaseRepo", err) - return nil - } + if ci.HeadUser.ID == baseRepo.OwnerID { + ci.HeadRepo = baseRepo + } else { + // TODO: forked's fork + ci.HeadRepo = repo_model.GetForkedRepo(ctx, ci.HeadUser.ID, baseRepo.ID) + if ci.HeadRepo == nil { + // TODO: based's base? + err = baseRepo.GetBaseRepo(ctx) + if err != nil { + ctx.ServerError("GetBaseRepo", err) + return nil + } - // Check if baseRepo's base repository is the same as headUser's repository. - if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != ci.HeadUser.ID { - log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.NotFound(nil) - return nil + // Check if baseRepo's base repository is the same as headUser's repository. + if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != ci.HeadUser.ID { + log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) + ctx.NotFound(nil) + return nil + } + // Assign headRepo so it can be used below. + ci.HeadRepo = baseRepo.BaseRepo } - // Assign headRepo so it can be used below. - ci.HeadRepo = baseRepo.BaseRepo } } else { if compareReq.HeadOwner == ctx.Repo.Owner.Name && compareReq.HeadRepoName == ctx.Repo.Repository.Name {