Prevent server 500 on compare branches with no common history (#6555)

* Prevent 500 if there is no common mergebase
* Prevent creation of PR with no history
This commit is contained in:
zeripath 2019-04-09 21:45:58 +01:00 committed by GitHub
parent 7350e439bf
commit 89cc7c646d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 15 deletions

View file

@ -48,17 +48,22 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
prInfo := new(PullRequestInfo)
prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch)
if err != nil {
return nil, fmt.Errorf("GetMergeBase: %v", err)
}
logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
if err != nil {
return nil, err
}
prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs)
if err != nil {
return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err)
if err == nil {
// We have a common base
logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
if err != nil {
return nil, err
}
prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs)
if err != nil {
return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err)
}
} else {
prInfo.Commits = list.New()
prInfo.MergeBase, err = GetFullCommitID(repo.Path, remoteBranch)
if err != nil {
prInfo.MergeBase = remoteBranch
}
}
// Count number of changed files.