always use headCommitID for review comment diff (#14011)

This commit is contained in:
Jimmy Praet 2020-12-16 11:50:30 +01:00 committed by GitHub
parent 7f85728cf9
commit a728d1e046
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,16 +167,16 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
// Only fetch diff if comment is review comment // Only fetch diff if comment is review comment
if len(patch) == 0 && reviewID != 0 { if len(patch) == 0 && reviewID != 0 {
if len(commitID) == 0 { headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
commitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil { if err != nil {
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
} }
if len(commitID) == 0 {
commitID = headCommitID
} }
patchBuf := new(bytes.Buffer) patchBuf := new(bytes.Buffer)
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, commitID, git.RawDiffNormal, treePath, patchBuf); err != nil { if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, patchBuf); err != nil {
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, commitID, treePath, err) return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err)
} }
patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines) patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
} }