Skip to content

"Revert" button disappears when it shouldn't

Summary

When reverting a Merge Request, if the user checks "Start a new merge request with these changes", but then clicks "Cancel" when creating the new Merge Request, the original Merge Request no longer has the "Revert" button.

Steps to reproduce

  1. Create a Merge Request on a project
  2. Merge the Merge Request
  3. Click the Revert button on the Merge Request
  4. Check the box for "Start a new merge request with these changes"
  5. On the next screen for creating the new Merge Request, click Cancel
  6. Go back to the previous Merge Request. The Revert button is no longer there

Expected behavior

I would expect to still see the Revert button since the Merge Request has not been reverted yet.

Actual behavior

The Revert button disappears

Possible fixes

The problem is that the Revert button creates a Revert commit even if the new Merge Request is not created. Therefore MergeRequest#can_be_reverted? returns false because it detects a Revert commit is already present in the repository.

Two possible solutions I can think of:

  1. Rather than just checking for a Revert commit, check to see if that Revert commit is either on the master branch, or has a Merge Request assigned to it.
  2. If a Revert commit has been created, link to that commit on the Merge Request page, so at least the user can view the commit and create a new Merge Request if desired (see gitlab-ce#13997)

Workaround

Although this won't get the Revert button back on the original MR page, the following steps allow you to recreate the revert MR.

  1. The original MR will get a system note, click the commit in the system note. Screenshot_2023-07-06_at_12.02.56
  2. Click the branch tag on the commit page Screenshot_2023-07-06_at_12.07.47
  3. Click the Create merge request button from the branch page.

Another way, since a branch is created, go to active branches for the project, view the revert branch named revert-<merge_commit_sha> and create a merge request from there

Edited by Jay McCure