xref: /aosp_15_r20/external/arm-trusted-firmware/docs/process/commit-style.rst (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong ParkCommit Style
2*54fd6939SJiyong Park============
3*54fd6939SJiyong Park
4*54fd6939SJiyong ParkWhen writing commit messages, please think carefully about the purpose and scope
5*54fd6939SJiyong Parkof the change you are making: describe briefly what the change does, and
6*54fd6939SJiyong Parkdescribe in detail why it does it. This helps to ensure that changes to the
7*54fd6939SJiyong Parkcode-base are transparent and approachable to reviewers, and it allows us to
8*54fd6939SJiyong Parkkeep a more accurate changelog. You may use Markdown in commit messages.
9*54fd6939SJiyong Park
10*54fd6939SJiyong ParkA good commit message provides all the background information needed for
11*54fd6939SJiyong Parkreviewers to understand the intent and rationale of the patch. This information
12*54fd6939SJiyong Parkis also useful for future reference.
13*54fd6939SJiyong Park
14*54fd6939SJiyong ParkFor example:
15*54fd6939SJiyong Park
16*54fd6939SJiyong Park- What does the patch do?
17*54fd6939SJiyong Park- What motivated it?
18*54fd6939SJiyong Park- What impact does it have?
19*54fd6939SJiyong Park- How was it tested?
20*54fd6939SJiyong Park- Have alternatives been considered? Why did you choose this approach over
21*54fd6939SJiyong Park  another one?
22*54fd6939SJiyong Park- If it fixes an `issue`_, include a reference.
23*54fd6939SJiyong Park
24*54fd6939SJiyong Park|TF-A| follows the `Conventional Commits`_ specification. All commits to the
25*54fd6939SJiyong Parkmain repository are expected to adhere to these guidelines, so it is
26*54fd6939SJiyong Park**strongly** recommended that you read at least the `quick summary`_ of the
27*54fd6939SJiyong Parkspecification.
28*54fd6939SJiyong Park
29*54fd6939SJiyong ParkTo briefly summarize, commit messages are expected to be of the form:
30*54fd6939SJiyong Park
31*54fd6939SJiyong Park.. code::
32*54fd6939SJiyong Park
33*54fd6939SJiyong Park    <type>[optional scope]: <description>
34*54fd6939SJiyong Park
35*54fd6939SJiyong Park    [optional body]
36*54fd6939SJiyong Park
37*54fd6939SJiyong Park    [optional footer(s)]
38*54fd6939SJiyong Park
39*54fd6939SJiyong ParkThe following example commit message demonstrates the use of the
40*54fd6939SJiyong Park``refactor`` type and the ``amu`` scope:
41*54fd6939SJiyong Park
42*54fd6939SJiyong Park.. code::
43*54fd6939SJiyong Park
44*54fd6939SJiyong Park    refactor(amu): factor out register accesses
45*54fd6939SJiyong Park
46*54fd6939SJiyong Park    This change introduces a small set of register getters and setters to
47*54fd6939SJiyong Park    avoid having to repeatedly mask and shift in complex code.
48*54fd6939SJiyong Park
49*54fd6939SJiyong Park    Change-Id: Ia372f60c5efb924cd6eeceb75112e635ad13d942
50*54fd6939SJiyong Park    Signed-off-by: Chris Kay <[email protected]>
51*54fd6939SJiyong Park
52*54fd6939SJiyong ParkThe following `types` are permissible and are strictly enforced:
53*54fd6939SJiyong Park
54*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
55*54fd6939SJiyong Park| Scope        | Description                                                   |
56*54fd6939SJiyong Park+==============+===============================================================+
57*54fd6939SJiyong Park| ``feat``     | A new feature                                                 |
58*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
59*54fd6939SJiyong Park| ``fix``      | A bug fix                                                     |
60*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
61*54fd6939SJiyong Park| ``build``    | Changes that affect the build system or external dependencies |
62*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
63*54fd6939SJiyong Park| ``ci``       | Changes to our CI configuration files and scripts             |
64*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
65*54fd6939SJiyong Park| ``docs``     | Documentation-only changes                                    |
66*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
67*54fd6939SJiyong Park| ``perf``     | A code change that improves performance                       |
68*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
69*54fd6939SJiyong Park| ``refactor`` | A code change that neither fixes a bug nor adds a feature     |
70*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
71*54fd6939SJiyong Park| ``revert``   | Changes that revert a previous change                         |
72*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
73*54fd6939SJiyong Park| ``style``    | Changes that do not affect the meaning of the code            |
74*54fd6939SJiyong Park|              | (white-space, formatting, missing semi-colons, etc.)          |
75*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
76*54fd6939SJiyong Park| ``test``     | Adding missing tests or correcting existing tests             |
77*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
78*54fd6939SJiyong Park| ``chore``    | Any other change                                              |
79*54fd6939SJiyong Park+--------------+---------------------------------------------------------------+
80*54fd6939SJiyong Park
81*54fd6939SJiyong ParkThe permissible `scopes` are more flexible, and we maintain a list of them in
82*54fd6939SJiyong Parkour :download:`Commitizen configuration file <../../.cz.json>`. Scopes in this
83*54fd6939SJiyong Parkfile are organized by their changelog section, each of which may have one or
84*54fd6939SJiyong Parkmore accepted scopes, but only the first of which is considered to be "blessed".
85*54fd6939SJiyong ParkScopes that are not blessed exist for changes submitted before scope enforcement
86*54fd6939SJiyong Parkcame into effect, and are considered deprecated.
87*54fd6939SJiyong Park
88*54fd6939SJiyong ParkWhile we don't enforce scopes strictly, we do ask that commits use these if they
89*54fd6939SJiyong Parkcan, or add their own if no appropriate one exists (see :ref:`Adding Scopes`).
90*54fd6939SJiyong Park
91*54fd6939SJiyong ParkIt's highly recommended that you use the tooling installed by the optional steps
92*54fd6939SJiyong Parkin the :ref:`prerequisites <Prerequisites>` guide to validate commit messages
93*54fd6939SJiyong Parklocally, as commitlint reports a live list of the acceptable scopes.
94*54fd6939SJiyong Park
95*54fd6939SJiyong Park.. _Adding Scopes:
96*54fd6939SJiyong Park
97*54fd6939SJiyong ParkAdding Scopes
98*54fd6939SJiyong Park-------------
99*54fd6939SJiyong Park
100*54fd6939SJiyong ParkScopes that are either a) unblessed in the configuration file, or b) do not
101*54fd6939SJiyong Parkexist in the configuration file at all are considered to be deprecated. If you
102*54fd6939SJiyong Parkare adding a new component that does not yet have a designated scope, please
103*54fd6939SJiyong Parkfeel free to add one.
104*54fd6939SJiyong Park
105*54fd6939SJiyong ParkFor example, if you are adding or making modifications to `Foo`'s latest and
106*54fd6939SJiyong Parkgreatest new platform `Bar`, you would add it to the `Platforms` changelog
107*54fd6939SJiyong Parksection, and the hierarchy should look something like this:
108*54fd6939SJiyong Park
109*54fd6939SJiyong Park.. code:: json
110*54fd6939SJiyong Park
111*54fd6939SJiyong Park    {
112*54fd6939SJiyong Park        "sections": [
113*54fd6939SJiyong Park            {
114*54fd6939SJiyong Park                "title": "Platforms",
115*54fd6939SJiyong Park                "sections": [
116*54fd6939SJiyong Park                    {
117*54fd6939SJiyong Park                        "title": "Foo",
118*54fd6939SJiyong Park                        "scopes": ["foo"],
119*54fd6939SJiyong Park                        "sections": [
120*54fd6939SJiyong Park                            {
121*54fd6939SJiyong Park                                "title": "Bar",
122*54fd6939SJiyong Park                                "scopes": ["bar"]
123*54fd6939SJiyong Park                            }
124*54fd6939SJiyong Park                        ]
125*54fd6939SJiyong Park                    }
126*54fd6939SJiyong Park                ]
127*54fd6939SJiyong Park            }
128*54fd6939SJiyong Park        ]
129*54fd6939SJiyong Park    }
130*54fd6939SJiyong Park
131*54fd6939SJiyong ParkWhen creating new scopes, try to keep them short and succinct, and use kebab
132*54fd6939SJiyong Parkcase (``this-is-kebab-case``). Components with a product name (i.e. most
133*54fd6939SJiyong Parkplatforms and some drivers) should use that name (e.g. ``gic600ae``,
134*54fd6939SJiyong Park``flexspi``, ``stpmic1``), otherwise use a name that uniquely represents the
135*54fd6939SJiyong Parkcomponent (e.g. ``marvell-comphy-3700``, ``rcar3-drivers``, ``a3720-uart``).
136*54fd6939SJiyong Park
137*54fd6939SJiyong ParkMandated Trailers
138*54fd6939SJiyong Park-----------------
139*54fd6939SJiyong Park
140*54fd6939SJiyong ParkCommits are expected to be signed off with the ``Signed-off-by:`` trailer using
141*54fd6939SJiyong Parkyour real name and email address. You can do this automatically by committing
142*54fd6939SJiyong Parkwith Git's ``-s`` flag.
143*54fd6939SJiyong Park
144*54fd6939SJiyong ParkThere may be multiple ``Signed-off-by:`` lines depending on the history of the
145*54fd6939SJiyong Parkpatch, but one **must** be the committer. More details may be found in the
146*54fd6939SJiyong Park`Gerrit Signed-off-by Lines guidelines`_.
147*54fd6939SJiyong Park
148*54fd6939SJiyong ParkEnsure that each commit also has a unique ``Change-Id:`` line. If you have
149*54fd6939SJiyong Parkfollowed optional steps in the prerequisites to either install the Node.js tools
150*54fd6939SJiyong Parkor clone the repository using the "`Clone with commit-msg hook`" clone method,
151*54fd6939SJiyong Parkthen this should be done automatically for you.
152*54fd6939SJiyong Park
153*54fd6939SJiyong ParkMore details may be found in the `Gerrit Change-Ids documentation`_.
154*54fd6939SJiyong Park
155*54fd6939SJiyong Park--------------
156*54fd6939SJiyong Park
157*54fd6939SJiyong Park*Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.*
158*54fd6939SJiyong Park
159*54fd6939SJiyong Park.. _Conventional Commits: https://www.conventionalcommits.org/en/v1.0.0
160*54fd6939SJiyong Park.. _Gerrit Change-Ids documentation: https://review.trustedfirmware.org/Documentation/user-changeid.html
161*54fd6939SJiyong Park.. _Gerrit Signed-off-by Lines guidelines: https://review.trustedfirmware.org/Documentation/user-signedoffby.html
162*54fd6939SJiyong Park.. _issue: https://developer.trustedfirmware.org/project/board/1/
163*54fd6939SJiyong Park.. _quick summary: https://www.conventionalcommits.org/en/v1.0.0/#summary
164