1# Contributing Guidelines
2
3This document attempts to outline some basic rules to follow when contributing
4to OpenBMC's IPMI stack. It does _not_ outline coding style; we follow the
5[OpenBMC C++ style guide](https://github.com/openbmc/docs/blob/master/cpp-style-and-conventions)
6for that.
7
8## Organizing Commits
9
10A good commit does exactly one thing. We prefer many small, atomic commits to
11one large commit which makes many functional changes.
12
13- Too large: "convert foo to new API; also fix CVE 1234 in bar"
14- Too small: "move abc.h to top of include list" and "move xyz.h to bottom of
15  include list"
16- Just right: "convert foo to new API" and "convert foo from tab to space"
17
18Often, creating small commits this way results in a number of commits which are
19dependent on prior commits; Gerrit handles this situation well, so feel free to
20push commits which are based on your change still in review. However, when
21possible, your commit should stand alone on top of master - "Fix whitespace in
22bar()" does not need to depend on "refactor foo()". Said differently, ensure
23that topics which are not related to each other semantically are also not
24related to each other in Git until they are merged into master.
25
26When pushing a stack of patches (current branch is >1 commits ahead of
27origin/master), these commits will show up with that same relationship in
28gerrit. This means that each patch must be merged in order of that relationship.
29So if one of the patches in the middle needs to be changed, all the patches from
30that point on would need to be pushed to maintain the relationship. This will
31effectively rebase the unchanged patches, which would in turn trigger a new CI
32build. Ideally, changes from the entire patchset could be done all in one go to
33reduce unnecessary rebasing.
34
35When someone makes a comment on your commit in Gerrit, modify that commit and
36send it again to Gerrit. This typically involves `git rebase --interactive` or
37`git commit --amend`, for which there are many guides online. As mentioned in
38the paragraph above, when possible you should make changes to multiple patches
39in the same stack before you push, in order to minimize CI and notification
40churn from the rebase operations.
41
42Commits which include changes that can be tested by a unit test should also
43include a unit test to exercise that change, within the same commit. Unit tests
44should be clearly written - even moreso than production code, unit tests are
45meant primarily to be read by humans - and should test both good and bad
46behaviors. Refer to the
47[testing documentation](https://github.com/openbmc/phosphor-host-ipmid/blob/master/docs/testing.md)
48for help writing tests, as well as best practices.
49
50## Formatting Commit Messages
51
52Your commit message should explain:
53
54- Concisely, _what_ change are you making? e.g. "docs: convert from US to UK
55  spelling" This first line of your commit message is the subject line.
56- Comprehensively, _why_ are you making that change? In some cases, like a small
57  refactor, the why is fairly obvious. But in cases like the inclusion of a new
58  feature, you should explain why the feature is needed.
59- Concisely, _how_ did you test? This comes in the form of a "Tested:" footer in
60  your commit message and is required for all code changes in the IPMI stack. It
61  typically consists of copy-pasted ipmitool requests and responses. When
62  possible, use the high-level ipmitool commands (e.g. "ipmitool sensor read
63  0x1"). In cases where that's not possible, or when testing edge or error
64  cases, it is acceptable to use "ipmitool raw" - but an explanation of your
65  output is appreciated. If the change can be validated entirely by running unit
66  tests, say so in the "Tested:" tag.
67
68Try to include the component you are changing at the front of your subject line;
69this typically comes in the form of the class, module, handler, or directory you
70are modifying. e.g. "apphandler: refactor foo to new API"
71
72Loosely, we try to follow the 50/72 rule for commit messages - that is, the
73subject line should not exceed 50 characters and the body should not exceed 72
74characters. This is common practice in many projects which use Git.
75
76All commit messages must include a Signed-off-by line, which indicates that you
77the contributor have agreed to the Developer Certificate of Origin. This line
78must include the name you commonly use, often a given name and a family name or
79surname. (ok: A. U. Thor, Sam Samuelsson, robert a. heinlein; not ok: xXthorXx,
80Sam, RAH)
81
82## Sending Patches
83
84Like most projects in OpenBMC, we use Gerrit to review patches. Please check the
85MAINTAINERS file to determine who needs to approve your review in order for your
86change to be merged. Submitters will need to manually add their reviewers in
87Gerrit; reviewers are not currently added automatically. Maintainers may not see
88the commit if they have not been added to the review!
89
90## Pace of Review
91
92Contributors who are used to code reviews by their team internal to their own
93company, or who are not used to code reviews at all, are sometimes surprised by
94the pace of code reviews in open source projects. Try to keep in mind that those
95reviewing your patch may be contributing to OpenBMC in a volunteer or
96partial-time capacity, may be in a timezone far removed from your own, and may
97have very deep review queues already of patches which have been waiting longer
98than yours.
99
100If you feel your patch has been missed entirely, of course it's alright to email
101the maintainers (addresses available in MAINTAINERS file) - but a reasonable
102timeframe to do so is on the order of a week, not on the order of hours.
103
104Additionally, the IPMI stack has a set of policies for when and how changes can
105be approved; please check the MAINTAINERS file for the full list ("Change
106approval rules").
107
108The maintainers' job is to ensure that incoming patches are as correct and easy
109to maintain as possible. Part of the nature of open source is attrition -
110contributors can come and go easily - so maintainers tend not to put stock in
111promises such as "I will add unit tests in a later patch" or "I will be
112implementing this proposal by the end of next month." This often manifests as
113reviews which may seem harsh or exacting; please keep in mind that the community
114is trying to collaborate with you to build a patch that will benefit the project
115on its own.
116
117## Code of Conduct
118
119We enthusiastically adhere to the same
120[Code of Conduct](https://github.com/openbmc/docs/blob/master/code-of-conduct.md)
121as the rest of OpenBMC. If you have any concerns, please check that document for
122guidelines on who can help you resolve them.
123