]> source.dussan.org Git - gitea.git/commitdiff
Don't ignore error in getMergeCommit (#1843)
authorEthan Koenig <etk39@cornell.edu>
Thu, 1 Jun 2017 00:51:24 +0000 (20:51 -0400)
committerBo-Yi Wu <appleboy.tw@gmail.com>
Thu, 1 Jun 2017 00:51:24 +0000 (19:51 -0500)
models/pull.go

index e85bf56c613400f06f09a486534aed597f037f57..7a636c3c8c1f488c024392bac8020a349615586a 100644 (file)
@@ -501,9 +501,15 @@ func (pr *PullRequest) getMergeCommit() (*git.Commit, error) {
                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
-       commitID, _ := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
-       cmd := string(commitID)[:40] + ".." + pr.BaseBranch
+       commitIDBytes, err := ioutil.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
+       if err != nil {
+               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
        mergeCommit, stderr, err := process.GetManager().ExecDirEnv(-1, "", fmt.Sprintf("isMerged (git rev-list --ancestry-path --merges --reverse): %d", pr.BaseRepo.ID),