@@ -499,9 +499,15 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
499
499
return nil , fmt .Errorf ("git merge-base --is-ancestor: %v %v" , stderr , err )
500
500
}
501
501
502
- // We can ignore this error since we only get here when there's a valid commit in headFile
503
- commitID , _ := ioutil .ReadFile (pr .BaseRepo .RepoPath () + "/" + headFile )
504
- cmd := string (commitID )[:40 ] + ".." + pr .BaseBranch
502
+ commitIDBytes , err := ioutil .ReadFile (pr .BaseRepo .RepoPath () + "/" + headFile )
503
+ if err != nil {
504
+ return nil , fmt .Errorf ("ReadFile(%s): %v" , headFile , err )
505
+ }
506
+ commitID := string (commitIDBytes )
507
+ if len (commitID ) < 40 {
508
+ return nil , fmt .Errorf (`ReadFile(%s): invalid commit-ID "%s"` , headFile , commitID )
509
+ }
510
+ cmd := commitID [:40 ] + ".." + pr .BaseBranch
505
511
506
512
// Get the commit from BaseBranch where the pull request got merged
507
513
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) {
510
516
511
517
if err != nil {
512
518
return nil , fmt .Errorf ("git rev-list --ancestry-path --merges --reverse: %v %v" , stderr , err )
519
+ } else if len (mergeCommit ) < 40 {
520
+ // PR was fast-forwarded, so just use last commit of PR
521
+ mergeCommit = commitID [:40 ]
513
522
}
514
523
515
524
gitRepo , err := git .OpenRepository (pr .BaseRepo .RepoPath ())
0 commit comments