Skip to content

Commenting on MR diffs when branches do not have the same tree breaks

Summary

Commenting on MR diffs when branches do not have the same git tree seems to create some undefined behaviors regarding where the comment is stored and what it points to.

Steps to reproduce

  1. Create a new repository on GitLab
  2. Create a file on master, like a README.md with some random content
  3. Locally git init a new project (do not pull the project from gitlab)
  4. Create a new branch like request_branch, add and commit something like CHANGELOG.md with a couple lines in it
  5. Add GitLab as a remote and push that branch to your repo
  6. Create a MR to master
  7. Add comments on the diff in the MR
  8. Refresh the page

Example Project

See the following MR: crobin/bug-repo-diff-comment!1

What is the current bug behavior?

2 behavior seen:

  • GitLab.com: Allows the user to put the comment, but somehow after refreshing the comments are not visible in the diff and the Discussion tab reports the comments as being on an old version of the diff.

  • GitLab CE 10.3.2: Nothing seems to happen.

What is the expected correct behavior?

The comments should be properly assigned to the diff and show up inside it.

Relevant logs and/or screenshots

HTTP logs on GitLab CE 10.3.2

Request

utf8:✓
authenticity_token:<redacted>
view:inline
line_type:new
merge_request_diff_head_sha:e768755054c1ebd54eb5141159032d5f2b5c4f2b
in_reply_to_discussion_id:
note_project_id:
target_type:merge_request
target_id:11754
note[noteable_type]:MergeRequest
note[noteable_id]:11754
note[commit_id]:
note[type]:DiffNote
note[line_code]:272321bdea0b8cec2310fbeb2df481796802508a_0_5
note[position]:{"base_sha":null,"start_sha":"0a9852c66d0d56c3351cb26fdbacce560d12e1ba","head_sha":"e768755054c1ebd54eb5141159032d5f2b5c4f2b","old_path":"History.md","new_path":"History.md","position_type":"text","old_line":null,"new_line":5}
note[note]:Game name needs to be changed

Response

{"commands_changes":null,"valid":false,"errors":{"diff_line":["can't be blank"],"line_code":["can't be blank","must be a 
 valid line code"]}}

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

N/A

Results of GitLab application Check

N/A

Possible fixes

None