Skip to content

Code comment on an unchanged line shows the wrong code context #39794

Open

Description

@cedric-roussel

Gitea Version

1.27.3 - main

What happened?

I comment on an unchanged line in a pull request diff.
The Files tab shows it in the right place.
The Conversation tab, the notification mail shows it at the wrong place.

Steps to reproduce:

  1. On the base branch, commit file.txt with 20 lines old 1 … old 20.
  2. In a second commit, insert 5 lines at the top. old 10 is now line 15.
  3. On a new branch, change only the last line and open a PR.
  4. In the Files tab, expand the hidden lines and comment on line 15 (old 10).
  5. In the Conversation tab, the context above the comment ends with old 15 instead of old 10.

Conversation tab:
Image

File tab:
Image

Relates to:
#35662

How are you running Gitea?

docker

Activity

  1. cedric-roussel commented on Oct 15, 2026

    @cedric-roussel
    Author

    AI suggested fix:

    diff --git a/services/pull/review.go b/services/pull/review.go
    index 9972f1a14..353654b5b 100644
    --- a/services/pull/review.go
    +++ b/services/pull/review.go
    @@ -276,7 +276,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
    
                    // If patch is still empty (unchanged line), generate code context
                    if patch == "" && commitID != "" {
    -                       patch, err = gitdiff.GeneratePatchForUnchangedLine(ctx, gitRepo, commitID, treePath, line, setting.UI.CodeCommentLines)
    +                       patch, err = gitdiff.GeneratePatchForUnchangedLine(ctx, gitRepo, headCommitID, treePath, line, setting.UI.CodeCommentLines)
                            if err != nil {
                                    // Log the error but don't fail comment creation
                                    log.Debug("Unable to generate patch for unchanged line (file=%s, line=%d, commit=%s): %v", treePath, line, commitID, err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions