Date Published: March 16, 2022
How to apply and test a patch from drupal.org using Git on Acquia Cloud
Code doesn't always work the way you expect it to. Sometimes you're going to have to use a patch.
Important
Acquia's Remote Administration (RA) service requires customers to follow specific steps when applying patches, to make sure that changes are not overwritten by RA updates. For more information, see Patching and locking modules.
Important
If you are using Drupal 8 and above using Composer please see Patching and locking modules.
Here are the steps for applying and testing a patch to a contributed module in your development environment on Acquia Cloud while using Git. These directions are also applicable to SVN users, but the repository-specific commands are different.
Note
For information and resources about Git, see the Git basics article.
- Sign in to Acquia, and then view your environments on the Cloud > Workflow page.
- Back up your database. (You can also use this as an opportunity to back up your website's files)
- Copy your production database back to the development environment.
- Clone (if necessary) and check out your repository, based on if you have cloned it locally or not:
- Change the directory to be inside the repository folder that you just created.
- Create a new branch locally.
git checkout -b [new descriptive branch name]
- If this is a patch for a contributed module, change to that module's directory.
- Apply the patch.
You can download the patch to a temporary location such as your docroot's temp directory:
curl -s https://www.drupal.org/files/issues/[patch_name].patch > /tmp/patchfile.patch
Run a test to ensure the patch will apply cleanly.
patch -p1 --dry-run < /tmp/patchfile.patch
If this returns positive results, you can then apply the patch and remove the file.
patch -p1 < /tmp/patchfile.patchrm /tmp/patchfile.patch
Note
You can also combine all of these steps into a single command, which executes the test and applies the patch if the dry run completes normally:
# The && syntax ensures the next command only runs if the previous one was successful.curl -s https://www.drupal.org/files/issues/[patch_name].patch >/tmp/patchfile.patch && patch -p1 --dry-run < /tmp/patchfile.patch && patch -p1 < /tmp/patchfile.patch && rm /tmp/patchfile.patch
- Commit the change locally.
git commit -am \"Added patch for x issue\"
- Push the new branch to the git repository.
git push -u origin [branch name from step 5]
- Change the branch in development to the new one you created. You can do this on the Cloud > Workflow page.
- Test the patch in the development environment.
After you have completed your testing, you can then move the code into production. For information about patching Drupal, or patching using Git or SVN, you can also visit the Applying patches page on Drupal.org. For general information about Git, visit Git Immersion.
Did not find what you were looking for?
If this content did not answer your questions, try searching or contacting our support team for further assistance.