Patch workflow for contributing to Drupal 7
Inspired by https://pittet.ca/drupal/sprint/patch
One time clone of Drupal repo
git clone --branch 7.x https://git.drupal.org/project/drupal.git
One time create a branch that will take a test-only patch to confirm that it fails.
git branch test-only
See https://www.drupal.org/node/3060/git-instructions/7.x/nonmaintainer for other branches.
Workflow when also creating a test-only patch
A test only patch is useful for maintainers since it clearly demonstrates the problem, by failing, and then proves that the solution actually solves the problem illustrated by the test when the test-and-solution patch passes tests.
- Bring in latest changes from upstream
git fetch --all
- Create new branch for the issue you’re working on
git branch issue-description-1438940
- Create a fresh install of Drupal
drush si --db-url=mysql://user-name:user-pass@localhost/db-name --account-name=admin --account-pass=admin
- Enable simpletest
drush en -y simpletest
- Create a failing test that you will solve in the main issue branch. Add/commit/etc. Run the test with
php scripts/run-tests.sh --browser --verbose --url http://example.com/ --class "TestClass"
- Create a test-only failing patch. Get the latest from upstream, rebase, then make diff. This captures differences
only in the module test file.
git fetch --all && git rebase origin/7.x && git diff origin/7.x module-name.test > issue-description-1438940-13-test-only.patch
- Use
debug($variable)
to debug tests.
- Use
- Checkout the branch where you’ll solve the issue
git checkout issue-description-1438940
- Apply patch if you’re modifying one
curl http://drupal.org/files/patch-name-1438940-2.patch | git apply
- Commit that initial patch
git commit -m '[comment number]'
- Merge in the test from the test-only branch
git merge issue-description-1438940-test-only
- Do stuff! Add, modify, and make commits. Run the test until it passes.
- Get the latest from upstream again (things change fast!)
git fetch --all
- Rebase so that all commits made to your branch get added ahead of the most recent commit to the origin.
git rebase origin/7.x
- Make an interdiff, if that’s useful
git diff commit-with-original-patch > interdiff.txt
- Make a solution patch
git diff origin/7.x > patch-name-1438940-13-test-and-solution.patch
Now wait until the testbot approves!