repo/pull: detect case when no merge base found (#4434)

This commit is contained in:
Unknwon
2017-06-05 00:10:53 -04:00
parent 02a576a6a0
commit 36d6450977
11 changed files with 94 additions and 67 deletions

View File

@@ -48,3 +48,14 @@ func IsErrUnsupportedVersion(err error) bool {
func (err ErrUnsupportedVersion) Error() string {
return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required)
}
type ErrNoMergeBase struct{}
func IsErrNoMergeBase(err error) bool {
_, ok := err.(ErrNoMergeBase)
return ok
}
func (err ErrNoMergeBase) Error() string {
return "no merge based found"
}

View File

@@ -10,7 +10,7 @@ import (
"time"
)
const _VERSION = "0.6.1"
const _VERSION = "0.6.2"
func Version() string {
return _VERSION

View File

@@ -22,7 +22,13 @@ type PullRequestInfo struct {
// GetMergeBase checks and returns merge base of two branches.
func (repo *Repository) GetMergeBase(base, head string) (string, error) {
stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path)
return strings.TrimSpace(stdout), err
if err != nil {
if strings.HasSuffix(err.Error(), " 1") {
return "", ErrNoMergeBase{}
}
return "", err
}
return strings.TrimSpace(stdout), nil
}
// GetPullRequestInfo generates and returns pull request information
@@ -47,7 +53,7 @@ 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)
return nil, err
}
logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)