diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 28d7379f07b8a..e76e854e066b1 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1240,6 +1240,13 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) return nil, nil, nil, "", "" } + if !(len(compareInfo.Commits) > 0) { + headGitRepo.Close() + ctx.Error(http.StatusUnprocessableEntity, "EmptyPullRequest", + fmt.Sprintf("no commits between %v:%v and %v:%v", baseRepo.Owner.Name, baseBranch, headUser.Name, headBranch)) + return nil, nil, nil, "", "" + } + return headRepo, headGitRepo, compareInfo, baseBranch, headBranch }