Skip to content

Commit a977ab7

Browse files
ethantkoenigappleboy
authored andcommitted
Don't ignore error in getMergeCommit (#1843)
1 parent 336e311 commit a977ab7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

models/pull.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,15 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
501501
return nil, fmt.Errorf("git merge-base --is-ancestor: %v %v", stderr, err)
502502
}
503503

504-
// We can ignore this error since we only get here when there's a valid commit in headFile
505-
commitID, _ := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
506-
cmd := string(commitID)[:40] + ".." + pr.BaseBranch
504+
commitIDBytes, err := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
505+
if err != nil {
506+
return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err)
507+
}
508+
commitID := string(commitIDBytes)
509+
if len(commitID) < 40 {
510+
return nil, fmt.Errorf(`ReadFile(%s): invalid commit-ID "%s"`, headFile, commitID)
511+
}
512+
cmd := commitID[:40] + ".." + pr.BaseBranch
507513

508514
// Get the commit from BaseBranch where the pull request got merged
509515
mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),

0 commit comments

Comments
 (0)