Creating and testing SVN patches using GitHub
Creating patch
A patch is a small piece of code that can be applied to fix a bug or add a new feature.
We will be creating an SVN patch from GitHub, as we have set up WordPress development from GitHub.
Step 1: Create a new feature branch from the master
- Creating a branch is required in case the patch has changes in multiple files; it will come in handy for code review. You can create a pull request and share the link in your ticket. But all changes still need to be sent by creating a patch and changes will be committed through SVN
git checkout master -b some-feature/123
Step 2: Add changes to staging area
- Once you are done with changes, you can stage them for the commit using the below command.
// Use git add . to stage all the unstage changes for commit.
git add .
Step 3: Commit changes
- Now, make the code changes you need to make and commit them (you can do several commits; it doesn’t matter):
// edit files
git commit -am "fixed the bug"
//edit more files
git commit -am "fixed edge case"
Step 4: Generate the patch
- You can generate an svn-compatible patch directly from Git as follows:
git diff master --no-prefix > ~/Downloads/123.diff
The –no-prefix flag is added so the patch does not show any source or destination prefix.
Testing the patch
In case you want to test a patch created by another, download the .diff file from the ticket and use the following command:
patch -p0 < ~/downloads/3124.diff
Once the patch is tested you can stash the changes by GitHub and pull the master for the latest changes and rebuild WordPress..on to the next ticket
References:
- https://make.wordpress.org/core/handbook/tutorials/working-with-patches/
- https://make.wordpress.org/core/handbook/tutorials/trac/submitting-a-patch/
- https://jonathanbossenger.com/submitting-a-patch-to-wordpress-core-using-git/
- https://make.xwp.co/2015/10/29/contributing-to-wordpress-core-via-github/