Fix fast-forward PR bug (#2137)
* Fix fast-forward PR bug * Don't ignore error in getMergeCommit (#1843)
This commit is contained in:
parent
6a6f0616f2
commit
9a7f59ef35
1 changed files with 12 additions and 3 deletions
|
@ -499,9 +499,15 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
|
||||||
return nil, fmt.Errorf("git merge-base --is-ancestor: %v %v", stderr, err)
|
return nil, fmt.Errorf("git merge-base --is-ancestor: %v %v", stderr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can ignore this error since we only get here when there's a valid commit in headFile
|
commitIDBytes, err := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
|
||||||
commitID, _ := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
|
if err != nil {
|
||||||
cmd := string(commitID)[:40] + ".." + pr.BaseBranch
|
return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err)
|
||||||
|
}
|
||||||
|
commitID := string(commitIDBytes)
|
||||||
|
if len(commitID) < 40 {
|
||||||
|
return nil, fmt.Errorf(`ReadFile(%s): invalid commit-ID "%s"`, headFile, commitID)
|
||||||
|
}
|
||||||
|
cmd := commitID[:40] + ".." + pr.BaseBranch
|
||||||
|
|
||||||
// Get the commit from BaseBranch where the pull request got merged
|
// Get the commit from BaseBranch where the pull request got merged
|
||||||
mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),
|
mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),
|
||||||
|
@ -510,6 +516,9 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v %v", stderr, err)
|
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v %v", stderr, err)
|
||||||
|
} else if len(mergeCommit) < 40 {
|
||||||
|
// PR was fast-forwarded, so just use last commit of PR
|
||||||
|
mergeCommit = commitID[:40]
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
|
gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
|
||||||
|
|
Reference in a new issue