Follow these guidelines to help the process of accepting merges to go smoothly for everyone:
-
Clone/fork the repository.
-
Create a new branch (
git checkout -b your_branch
). Name the branchbugfix/xxx
, if the contribution is a bug fix. Else, name the branchfeature/xxx
. Consistent naming of branches makes the output ofgit branch
easier to understand with a single glance. -
Do modifications on that branch. Except for special cases, the contribution should include proper unit tests and documentation. Follow the C++ and style guide below.
-
Make sure the modifications did not break anything by building and running the tests.
-
Check the quality of tests by collecting coverage. Make sure the tests cover 100% of the new code.
-
Commit the changes. Follow the Git commit guide below.
-
Push the changes to the remote branch (
git push origin your_branch
). -
Open a merge request against project's
main
branch.- Follow the link on your screen (after
git push
) to create a merge request. - Check "Delete source branch when merge request is accepted". Optionally, select a user to review your merge request in the "Assignee" menu.
- Proceed with "Submit merge request" button.
- Follow the link on your screen (after
-
Collaborate, implement suggestions, amend the branch.
- Do not use
using
directives in headers in global namespace. - Use
auto
if initialization already mentions type (like inauto v = std::make_shared<Type>()
). - Prefer
enum class
to C-styleenum
. - Use
std::optional<T>
to return a value of a function that may fail. - Never use exceptions.
Support for clang-format
will be added in the future.
Style conventions:
- Name case - see the table below.
- Project's
#include
s go first, then a blank line and system headers. Sort#include
s within each block in alphabetical order. - Avoid prefixes (like
m_
) and suffixes (like_num
or_str
) where possible. - If in doubt, use your own judgment and stick to the style of the surrounding code.
Name | Convention |
---|---|
Git branch | feature/branch-name or bugfix/branch-name |
File/directory | snake_case |
Class | snake_case |
Variable | snake_case |
Function | snake_case |
Macro/static constant | CAPITAL_SNAKE_CASE |
Template parameter | CamelCase |
These guidelines are an excerpt from the Pro Git Book.
-
Submissions should not contain any whitespace errors. Git provides an easy way to check for this — before you commit, run
git diff --check
, which identifies possible whitespace errors and lists them for you. -
Try to make each commit a logically separate changeset. If you can, try to make your changes digestible — don’t code for a whole weekend on five different issues and then submit them all as one massive commit on Monday. This approach also makes it easier to pull out or revert one of the changesets if you need to later.
-
Write a good commit message. As a general rule, your messages should start with a single line that’s no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation. Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug."
Model commit message
Short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 78
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug." This convention matches up with commit messages generated
by commands like git merge and git revert.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded by a
single space, with blank lines in between, but conventions vary here
- Use a hanging indent
Another example of acceptable commit message
Refactor the interface
- Rename elem to contains
- Rename subset to is_subset, and make is_subset applicable in infix notation
- Add the at_key method
- operator[] is now bound to at_key instead of find