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