Test patches

Final / Up to date -- Last peer review: 19 Sep 2014
Description: 
Test patches submitted to drupal.org for issues awaiting review.
Overview: 

In this lesson you will apply a patch that was submitted to resolve a reported issue (the issue has since been resolved; this lesson is for your practice).
After you get some practice, look in the Drupal 8 issue queue for patches that need review. Before patches get committed they must be reviewed and tested by members of the community. Testing patches is an easy way to help project maintainers resolve issues in the queue, and it doesn't require writing any code. You just need to understand the problem and know if it is resolved after the patch has been applied.

Resources
There is a short video, Test patches, that walks through this lesson.

Prerequisites: 
  • You'll be working with a sandbox version of Drupal in this exercise. It has been built with a known issue for you to observe. For this lesson, download and install Drupal 8 from the Drupal 8 Sandbox for Drupal Ladder, using the knowledge from the previous lessons.
  • Install Git
  • Basic Git knowledge is helpful but not required (Git Basics, Git Reference)
Steps: 

Before you begin, you can optionally run a few Git configuration commands to make Git more legible. You only need to do this once, and the options will be saved in your .gitconfig file. Open a terminal and type the following commands:
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global color.diff auto

  1. Using the command line, move into the Drupal 8 sandbox you have cloned if you are not already there, e.g. $ cd path/to/drupal-8/sandbox.
  2. Check which branch you are on with $ git branch
  3. If there's not an asterisk next to 8.x, you need to check out 8.x with $ git checkout 8.x
  4. Review the example issue on Drupal.org and find this problem in your locally installed sandbox site. (This is the sandbox issue that the lesson, Getting started in the issue queue is using. You can also read the real original issue for Drupal core.) You can read the patch by clicking on the patch file and opening it in your browser, or by opening it in a text editor after you have downloaded it.
    You may like to try Dreditor to review patches with it
  5. Download the patch in comment 2, which is the latest patch. You should place it in your local sandbox root directory. (Note: make sure that the file ends with .patch and not .txt. Some operating systems will append the .txt extension, so double-check it and correct it, if so.)
  6. In your sandbox site, go to the page where the changes will take effect by going to Content > + Add content > Article (node/add/article), and then scrolling down and clicking the URL path settings tab. The help text for that setting is what will be changing with the patch.
  7. Make sure you are in your sandbox root directory, where the patch file is located, and apply the patch by using the command git apply 1326088-rewrite-desription-for-url-alias.patch
  8. Refresh the page in your local sandbox site you have open in your browser (the node/add/* page) and confirm the issue has been resolved by seeing the help text change.
  9. If you were working on a real issue, you would now post a comment saying you have applied and tested the patch, and it resolves the problem.
  10. Once done testing, undo the changes applied by the patch with $ git reset --hard

Tips for testing more complex patches:

  • If your patch applies cleanly, but doesn't seem to work, try clearing your cache.
  • If clearing the cache doesn't work, check to see if the patch you applied requires database updates.
    Database updates are located in .install files. You can see the files modified by the patch with $ git diff --stat. Git will display a list of filenames with pluses and minuses, as shown in the picture below.
    Terminal 2014 less 2014 106ձ6
  • If an .install file was modified, run update.php by going to http://example.com/update.php
  • If you want to save a copy of your patched version of Drupal to continue working on this issue later, create a new branch and then commit the changes there. To do this, after applying the patch run the following commands:
    $ git checkout -b [issue-number]-[description]
    $ git commit -m 'Applying [patchname.patch] from http://drupal.org/node/[issue-number]-[comment-number]'
  • To see your branches do this: $ git branch
  • Now you can switch back and forth between Drupal's development branch (e.g. 8.x) and your own patched branch like this:
    • see available branches: $ git branch
    • check out out branch 8.x $ git checkout 8.x
    • check out your own branch: $ git checkout [name]

    Comments

    helenc's picture

    The installation process had removed write permissions from sites/default. As a result, when we got to

    git reset --hard

    We got the following error:
    error: unable to unlink old 'sites/default/default.settings.php' (Permission denied)

    As a beginner the word 'download' confused me. I was looking for a button called 'download' or when I right-clicked on the patch link I though there would be a 'download' option. I think it might be better to ask people to click on the link to see the patch and then to save it.

    You can download a patch using the command line in Linux:
    wget https://drupal.org/files/1326088-rewrite-desription-for-url-alias.patch

    gl2748's picture

    if you are doing this in windows 7 64bit when you download the patch it saves itself as: "1326088-rewrite-desription-for-url-alias"
    For some reason i kept getting the error message:
    fatal: cannot open patch '1326088-rewrite-desription-for-url-alias.patch' : no such file or directory
    I found that renaming the patch something simple like patchtest i.e. oneword, no special characters etc... worked...

    This patch isn't applying anymore. Probably time for a new test patch.

    Apply patch from comment number 2

    Lets say you apply a patch that has database changes and you run update.php.
    Now, if you want to work on this patch you create a new branch.
    And you can switch between the drupal8 and new branch, and this behaves like two different sets of source code that is working on a single database that was created for the initial drupal8 installation.
    Now, the question is, is it required to create a new database for the new branch, as there are changed done to the database by the patch.

    After going through this lesson you should be ready to tackle some real issues. A link should be included so novice users can help out with real projects:

    https://www.drupal.org/project/issues/search?text=&projects=&assigned=&s...

    The image below the text "Git will display a list of filenames with pluses and minuses, as shown in the picture below." does not work