Loading...


Related Products


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.

  1. Sign in to Acquia, and then view your environments on the Cloud > Workflow page.
  2. Back up your database. (You can also use this as an opportunity to back up your website's files)
  3. Copy your production database back to the development environment.
  4. Clone (if necessary) and check out your repository, based on if you have cloned it locally or not:
    • If you have not cloned your code repository locally, do that now. The following command will clone your repository and check out the production tag:
      git clone [site_Git_URL] [your production tag name]

      The repository folder is created wherever the command line was when the git clone command was run.

    • If you have already cloned your code repository locally, check out your production tag from your local Git repository location.
      git checkout [your production tag name]
  5. Change the directory to be inside the repository folder that you just created.
    cd [repositoryname]
  6. Create a new branch locally.
    git checkout -b [new descriptive branch name]
  7. If this is a patch for a contributed module, change to that module's directory.
  8. 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
  9. Commit the change locally.
    git commit -am \"Added patch for x issue\"
  10. Push the new branch to the git repository.
    git push -u origin [branch name from step 5]
  11. Change the branch in development to the new one you created. You can do this on the Cloud > Workflow page.
  12. 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.

Back to Section navigation