aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-04-09 21:45:58 +0100
committerGitHub <noreply@github.com>2019-04-09 21:45:58 +0100
commit89cc7c646deea10666fd7dc09c485e7910675cce (patch)
treeb58c1d778e920e9fe46d175ce7e6d28f77dc8fd2 /modules
parent7350e439bfa580d6693eac9848353e83e51a3525 (diff)
downloadgitea-89cc7c646deea10666fd7dc09c485e7910675cce.tar.gz
gitea-89cc7c646deea10666fd7dc09c485e7910675cce.zip
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
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo_pull.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/modules/git/repo_pull.go b/modules/git/repo_pull.go
index c6d97a6fd1..65c5414551 100644
--- a/modules/git/repo_pull.go
+++ b/modules/git/repo_pull.go
@@ -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.