The following principles were followed when writing this guide:
- Commits are associated with an issue in JIRA.
- Commits should be made in a branch and merged into master by a committer.
- The author and committer should not be the same person.
- Commits should retain the original author.
- Commits committed by a committer should include "Signed-off-by" in the message.
- Commits should include a link to the JIRA in the message.
- Commits should include unit tests.
File a JIRA
File a JIRA here describing the change you propose to make. It's usually a good idea to file a JIRA soon so that people are aware of the issue or proposal and can respond with comments.
Make sure that you have your
user.email configured in Git. This is so that the commits you make are attributed to you.
Both of these commands should return information. If they don't you can set each through the same commands and supplying your name and email. The name should be your full name.
Making Code Changes
If you have not already done so, get the code:
Make sure you're working with an up to date copy of the master branch, in case you cloned previously:
Create a branch for your change. This is very important, as it makes it easier to submit your patch later, especially if you end up creating multiple commits. Pick a name for the branch that will help you identify it. Naming the branch after the issue name in JIRA is one good option. For example, if you created issue DATAFU-123, you could name the branch DATAFU-123 or DATAFU-123-some-issue-description.
Make your code changes. You will be committing to your branch. It's fine to complete the code changes in multiple commits. These can be squashed together into a single commit when the patch is created.
All changes should also be unit tested. If you are fixing an issue then you should add tests that demonstrate the issue (i.e. test should fail). Your fix should make the tests pass. If you are submitting new code then you should write tests that fully test the functionality.
Preparing Code For Review
Once you think your code is ready for review you can create a patch. To do this, use the
format-patch command. This bundles together all the commits in your branch that are not in master into a single patch file.
Before creating the patch though, note whether you have multiple commits or not. If you do have multiple commits you should squash them into one so that the patch only consists of one commit. If you only have one commit then you can skip this step. We do this for the sake of having a clean commit history. Each issue should correspond to one commit. We can do this with a temporary throwaway branch. For example, if branch DATAFU-123 has our fix, we can create a branch DATAFU-123-squash and merge the changes into there.
Now create the patch. For issue DATAFU-123 we would name the patch DATAFU-123.patch:
Attach the patch to the JIRA you created.
If you created a squashed branch, such as DATAFU-123-squashed, you can delete it with this command:
Open a review board request here with a title such as "DATAFU-123 Some issue description". Upload your patch to the review board. Add a link for the review board you created in the JIRA issue. Be sure to add the group DataFu to the review board. This will cause the review request to be emailed to the DataFu dev mailing list.
Someone should respond to your request soon.
If you need to make additional changes (in response to feedback for example), you should append a version to any new patches you upload. For example, if a second patch was created for DATAFU-123 it could be named DATAFU-123-v2.patch. Attach the new patch to the JIRA and also upload it to Review Board.
How Code Gets Committed (by committers)
Once committers have signed off on your change, someone will commit the code to the master branch. Usually this will be one of the people who have reviewed the code and given their +1.
To commit the code, a committer would first start by creating a branch for the change. This is very important. You must create a branch before applying a patch. Otherwise the changes would be made directly to master.
For example, if the change was for issue DATAFU-123:
It's usually a good idea to check whether the patch will apply cleanly to the branch before proceeding:
Now the patch is committed to the branch. Note that we add the
-signoff flag so that a sign off message is added to the commit. This is important as it keeps a record of who acutally committed the change, as opposed to the author. The patch retains the original author.
The patch should apply cleanly if it was generated based on an up to date copy of master. If there are conflicts then try to resolve them, if possible. If resolving the conflicts is too complicated then raise this with the author and have them update their branch to master.
Run the unit tests. At the very least run the unit tests associated with the change.
To merge in the changes, simply merge the branch back into master and push. For example, for branch DATAFU-123:
Now delete the branch: