Recovering from a gitlab MR patch link rebase on a Drupal issue

Let me first preface this by saying that, as documented here, you should not put a gitlab MR patch link directly into your compose.json file. Instead you should download the patch file, and inlude it locally. Otherwise the patch is likely to change our from under you when the MR gets rebased onto another branch.

Unfortunately I didn't know that, and after fixing an urgent bug, our CI stopped building. It was late at night, and not a great time to be fixing the issue, so that added a layer of stress to it, as evidenced by a few panicked comments on the merge request. Still in the end, I got the patch recreated. In case you made the same mistake I did; here are the steps I took to recreate the patch:

  1. Find the commit that you believe to be the last known patch that applied to your site (77e55a in my case)
  2. git clone the repo for Drupal core or the module that this issue is relevant to
  3. git fetch origin <commit sha>
  4. git checkout <commit sha>
  5. git diff <name of tag representing your currently installed version> > <patch-file-name>.patch
  6. It is likely that this patch includes a whole bunch of stuff that is not relevant to this MR so open up the MR page in gitlab, and open up the changes tab delete everything from diff --git <filename info> to the line before the next diff --git <filename info> for each file not listed in the changes tab on gitlab.
  7. Now you should be left with a patch file that represents only the changed relevant to your issue, and that apply to your current version. Add it to your composer.json, and do a composer install, make sure it applies, and test to make sure the fix works as it did.
  8. Make sure you include a link to the issue in your composer.json patches section or you may have a hell of a time finding the issue in the future when the issue has been committed or the patch stops applying for some other reason. Here is the example line in my composer.json for this one "fix css import getting messed up by the aggregator https://www.drupal.org/project/drupal/issues/2936067": "patches/css-import-fix.as_of_210930.patch"

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.