Patches and pull requests are the best ways to contribute code back to CakePHP. Patches can be either attached to tickets in lighthouse. Pull requests can be created in github, and are generally a better way to contribute code.
Before working on patches for CakePHP, it’s a good idea to get your environment setup. You’ll need the following software:
Set up your user information with your name/handle and working email address:
git config --global user.name 'Bob Barker' git config --global user.email 'firstname.lastname@example.org'
If you are new to Git, we highly recommend you to read the excellent and free ProGit book.
Get a clone of the CakePHP source code from github:
After your fork is made, clone your fork to your local machine:
git clone email@example.com:YOURNAME/cakephp.git
Add the original CakePHP repository as a remote repository. You’ll use this later to fetch changes from the CakePHP repository. This will let you stay up to date with CakePHP:
cd cakephp git remote add upstream git://github.com/cakephp/cakephp.git
Each time you want to work on a bug, feature or enhancement create a topic branch.
The branch you create should be based on the version that your fix/enhancement is for. For example if you are fixing a bug in 2.3 you would want to use the 2.3 branch as the base for your branch. If your change is a bug fix for the current stable release, you should use the master branch. This makes merging your changes in later much simpler:
# fixing a bug on 2.3 git fetch upstream git checkout -b ticket-1234 upstream/2.3
Use a descriptive name for your branch, referencing the ticket or feature name is a good convention. e.g. ticket-1234, feature-awesome
The above will create a local branch based on the upstream (CakePHP) 2.3 branch. Work on your fix, and make as many commits as you need; but keep in mind the following:
Once your changes are done and you’re ready for them to be merged into CakePHP, you’ll want to update your branch:
git checkout 2.3 git fetch upstream git merge upstream/2.3 git checkout <branch_name> git rebase 2.3
This will fetch + merge in any changes that have happened in CakePHP since you started. It will then rebase - or replay your changes on top of the current code. You might encounter a conflict during the rebase. If the rebase quits early you can see which files are conflicted/un-merged with git status. Resolve each conflict, and then continue the rebase:
git add <filename> # do this for each conflicted file. git rebase --continue
Check that all your tests continue to pass. Then push your branch to your fork:
git push origin <branch-name>
Once your branch is on github, you can discuss it on the cakephp-core mailing list or submit a pull request on github.
When making pull requests you should make sure you select the correct base branch, as you cannot edit it once the pull request is created.
Remember that all code you contribute to CakePHP will be licensed under the MIT License, and the Cake Software Foundation will become the owner of any contributed code and all contributed code is subject to the Contributors license agreement.
All bug fixes merged into a maintenance branch will also be merged into upcoming releases periodically by the core team.