Skip to content
Versora

Manual

Review

Suggesting and applying changes

6 min read

On this page

Sometimes the most useful comment is the corrected code itself. A suggested change is a ```suggestion block inside a line comment, with the text that should take its place. Whoever receives the suggestion sees a diff (current lines → suggested lines) and applies it with one click. Several suggestions can go in a batch and become a single commit.

Suggesting a change

Where to find it

  • MR review › Changes tab › the line's + › comment box › Suggest change button ("Insert a suggestion block with the line's current content").

Step by step

  1. On the Changes tab, click the + of the line you want to replace.
  2. Click Suggest change. The app inserts the suggestion block with the line's current content into the text.
  3. Adjust the range, if the suggestion replaces more than one line: the Above and Below controls ("One more line: Above", "One line less: Below") increase and decrease the lines. The label shows the range ("Line 42" or "Lines 41–43").
  4. Edit the block's content with the code that should stay.
  5. Publish it like any comment: Start review / Add to review or Comment now (see Comments).

As long as you haven't edited the block's content, changing the range refills it with the new lines ("The content is refilled as long as you haven't edited it."). After you edit it, only the range changes.

ServiceHow far the range goes
GitLabUp to 100 lines above and below, within the file ("Limit: 100 lines above and below, within the file").
GitHubWithin the diff hunk ("On GitHub, the suggestion stays within the diff hunk").

Viewing and applying a suggestion

In threads, each suggestion block appears as Suggested change, with the file and the lines ("src/login.ts, lines 41–43") and the "Current lines and suggested lines" diff. A suggestion that deletes the lines shows "(deletes the lines)".

Suggestion buttons

ButtonWhat it does
Apply suggestionOpens the confirmation to apply just this one.
Add to batch / Remove from batchAdds the suggestion to the others in the batch, for a single commit.
AppliedMark of a suggestion that has already gone in.

While the app checks whether the suggestion still applies, you see "Checking the suggestion…". A suggestion in your unpublished draft shows "Draft: the suggestion can be applied once it's published.". On GitHub (and on GitLab without the suggestions API), the "commit and push by the app" mark also appears.

Step by step: applying

  1. Click Apply suggestion (one) or, with several in the batch, Apply batch… in the review header.
  2. The Apply the suggestion to !42? (or Apply 2 suggestions to !42?) dialog explains who makes the commit (see below) and lists each suggestion with the file, the lines, the author and the diff.
  3. Check the commit message:
    • on the server path (GitLab): Commit message (optional), "Empty: the project's default message";
    • on the app path: Commit message, already filled in. On GitLab, Apply 2 suggestion(s) to 1 file(s); on GitHub, Update login.ts (one suggestion) or Apply suggestions from code review, with a Co-authored-by for each suggestion author.
  4. Click Apply suggestion (or Apply 2 suggestions), or Ctrl+Enter in the message field.
  5. At the end:
    • GitLab: "Suggestion applied: GitLab created the commit on feature/login (!42)." or "2 suggestions applied in one commit on feature/login (!42).";
    • through the app: "Suggestion applied: commit 3f2a1b9c pushed to feature/login on origin.".

Clear empties the batch without applying anything.

Who makes the commit: GitLab or the app

GitLabGitHub
Who applies itThe server, through the suggestions API: "GitLab will create a commit on feature/login with this suggestion, mark it as applied and resolve the thread."The app: "The app will create the commit on top of a1b2c3d4 (the reviewed version), without touching your working directory or current branch, and push it to feature/login on origin. If the branch changed on the server, the push is rejected and nothing changes."
AfterwardsThe suggestion is marked as applied and the thread, resolved."GitHub has no API to apply suggestions, so the app makes the commit; the thread stays open and becomes outdated."

On a GitLab that doesn't expose suggestions in its API, the app does it the GitHub way: "This GitLab version doesn't expose suggestions in its API: the app makes the commit and the thread isn't marked as applied."

Suggestions from the two paths don't go in the same commit: "These suggestions can't go in the same commit (the server applies some, the app the others): apply them in separate batches."

When the suggestion can't be applied

The button is disabled, with the reason:

ReasonMeaning
"Already applied"It has already gone in.
"Outdated: the code changed after the suggestion"The line changed in a push after the comment.
"The server doesn't allow applying it (outdated, conflicting or no permission)"GitLab refused.
"The merge request isn't open"Closed or merged.
"Suggestion on the old side of the diff: it doesn't apply"The comment is on a removed line.
"The comment has more than one suggestion: apply it in the browser"More than one block in the same comment.
"The source branch is in another repository (fork): the app doesn't push to it"On the app path, there's no push to a fork.
"Suggestion outside a diff line"The comment isn't anchored to a line.

What Versora does in git

On the app path (GitHub, or GitLab without the suggestions API), the commit is built on top of the reviewed version, outside your working directory, and sent with a regular push, without force:

bash
# the new content becomes an object, assembled in a temporary index (your staging area isn't used)
git hash-object -w --stdin
git read-tree a1b2c3d4
git update-index --index-info
git write-tree
# the commit on top of the reviewed version, with the message from the dialog
git commit-tree <tree> -p a1b2c3d4 -F -
# regular push of the commit to the source branch
git push origin 3f2a1b9c:refs/heads/feature/login

Because the push is regular (without force), it only goes through if the branch on the server is still at a1b2c3d4. Your current branch, the staging area and the files on disk don't change.

On GitLab with the suggestions API, nothing runs in the local repository: the server creates the commit.

How to undo

The commit goes to the server: "the app's Ctrl+Z doesn't undo it (to go back, revert the commit)". See History.

Caveats and messages

  • "Some suggestions can no longer be applied (they were applied or became outdated) and were left out.": the MR changed while the dialog was open.
  • "The reviewed commit isn't in the local repository.": open the Changes tab so the app fetches the commits and try again.
  • "The push to feature/login was rejected: the branch changed on the server after the review was loaded. Nothing was changed; refresh the review and apply again.".
  • "Two suggestions change the same lines of src/login.ts: apply them one at a time.".
  • "Lines 41–43 of src/login.ts changed after the suggestion was made: it no longer applies. Refresh the review.".
  • "src/logo.png isn't a UTF-8 text file: the app can't apply the suggestion.".
  • "GitLab didn't let you apply the suggestions: you need to be the merge request author or have the Developer role (or higher) in the project.".
  • "Write the commit message.": on the app path, the message is required.

None in the app. The push on the local path goes through the server's usual credentials.

See also