xref: /src/CONTRIBUTING.md (revision 80950a079b20ed59616525fbca8ccaf3b6afcebc)
181ef45edSWarner Losh# Contribution Guidelines for GitHub
281ef45edSWarner Losh
381ef45edSWarner Losh## General Contributions to FreeBSD
481ef45edSWarner Losh
581ef45edSWarner LoshPlease read the guidelines in [Contributing to FreeBSD](https://docs.freebsd.org/en/articles/contributing/)
681ef45edSWarner Loshfor all the ways you can contribute to the project, how the project is organized,
781ef45edSWarner Loshhow to build different parts of the project, etc. The
881ef45edSWarner Losh[developer's handbook](https://docs.freebsd.org/en/books/developers-handbook/)
981ef45edSWarner Loshis another useful resource.
1081ef45edSWarner Losh
117f6a000fSEd MasteFreeBSD accepts source code contributions using one of several methods:
127f6a000fSEd Maste- A GitHub [pull request](https://github.com/freebsd/freebsd-src/pulls)
137f6a000fSEd Maste- A code review in [Phabricator](https://reviews.freebsd.org/differential)
147f6a000fSEd Maste- An attachment on a [Bugzilla ticket](https://bugs.freebsd.org)
157f6a000fSEd Maste- Direct access to the [Git repository](https://cgit.freebsd.org/src/)
167f6a000fSEd Maste
177f6a000fSEd MasteThe preferred method depends on a few factors including the size or scope of
187f6a000fSEd Mastethe change.  GitHub pull requests are preferred for relatively straightforward
197f6a000fSEd Mastechanges where the contributor already has a GitHub account.
207f6a000fSEd Maste
2167783db6SEd MasteA change should be submitted by only one method.  For example, please do not
2267783db6SEd Masteopen a GitHub pull request and create a Phabricator review for the same change
23*80950a07SWarner Losh(unless explicitly requested to do so by a FreeBSD committer). If asked to move
24*80950a07SWarner Loshfrom Github to Phabricator, please close the Github pull request adding the URL
25*80950a07SWarner Loshof the Phabricator review as a comment.
2667783db6SEd Maste
2781ef45edSWarner Losh## GitHub Pull Requests
2881ef45edSWarner Losh
2997beb0c9SEd MasteThe _freebsd-src_ GitHub repository is a **publish-only mirror** of the FreeBSD
3097beb0c9SEd Maste_src_ repository.  Pull Requests are accepted for **small, low-risk** changes
3197beb0c9SEd Mastethat require minimal review and integration effort.
3281ef45edSWarner Losh
3397beb0c9SEd MasteFor complex, controversial, security-related, or discussion-heavy changes, use
3497beb0c9SEd Mastethe normal FreeBSD review and development process (described below) instead.
3581ef45edSWarner Losh
3697beb0c9SEd MasteSubmit a Pull Request if your change:
3781ef45edSWarner Losh
3897beb0c9SEd Maste* Fixes a real, specific problem.
3997beb0c9SEd Maste* Is small in scope and easy to review.
4097beb0c9SEd Maste* Can be committed with **less than ~10 minutes** of additional work.
4197beb0c9SEd Maste* Passes all GitHub CI jobs.
4297beb0c9SEd Maste* Affects roughly **10 or fewer files** and **fewer than 200 lines of changes**.
4381ef45edSWarner Losh
4497beb0c9SEd Maste### When Not to use a Pull Request
45b2df9c07SWarner Losh
4697beb0c9SEd MasteDo NOT submit a Pull Request for:
4781ef45edSWarner Losh
4897beb0c9SEd Maste* Security-related changes.
4997beb0c9SEd Maste* Works in progress.
5097beb0c9SEd Maste* Changes that require design discussion, or are likely to be controversial.
5197beb0c9SEd Maste  (Start a mailing list thread to discuss the change first.)
5297beb0c9SEd Maste* Changes needing specialized or cross-subsystem review.
5397beb0c9SEd Maste* Large refactors or mechanical tree-wide changes.
5497beb0c9SEd Maste* Changes generated by AI tools without substantial human review and validation.
5581ef45edSWarner Losh
5697beb0c9SEd Maste### Preparing your Pull Request
5781ef45edSWarner Losh
5897beb0c9SEd MasteBefore submitting, ensure:
5997beb0c9SEd Maste
6097beb0c9SEd Maste#### Code Quality
6197beb0c9SEd Maste
6297beb0c9SEd Maste* The changes follow FreeBSD's style guide. See [Style](#Style).
6397beb0c9SEd Maste* _tools/build/checkstyle9.pl_ is run and:
6497beb0c9SEd Maste  * All errors are fixed, **or**
6597beb0c9SEd Maste  * Exceptions are documented in the PR.
6697beb0c9SEd Maste* No trailing whitespace is introduced.
6797beb0c9SEd Maste* Changes compile and work before submitting.
6897beb0c9SEd Maste* Test results (including Kyua tests) are unchanged, unless intentionally
6997beb0c9SEd Maste  modified.
7097beb0c9SEd Maste* Bug fixes include new test cases, when possible.
7197beb0c9SEd Maste
7297beb0c9SEd Maste#### Commit Structure
7397beb0c9SEd Maste
7497beb0c9SEd Maste* Each logical change is a **separate commit**.
7597beb0c9SEd Maste* Fixup commits are squashed into the commit they correct.
7697beb0c9SEd Maste* Each commit is suitable for direct inclusion in the FreeBSD's repository.
7797beb0c9SEd Maste* Pull Request scope must remain stable during review.  If feedback expands
7897beb0c9SEd Maste  scope, create a new Pull Request.
7997beb0c9SEd Maste* Rebase your chages (and update with a forced push) when incorporating review
8097beb0c9SEd Maste  feedback, rather than using a merge commit.
8197beb0c9SEd Maste
8297beb0c9SEd Maste#### Commit Messages
8397beb0c9SEd Maste
8497beb0c9SEd MasteEach commit must:
8597beb0c9SEd Maste
8697beb0c9SEd Maste* Follow the [commit log message guide](https://docs.freebsd.org/en/articles/committers-guide/#commit-log-message).
8797beb0c9SEd Maste* Include one ore more `Signed-off-by:` trailers certifying [Developer Certificate of Origin](https://developercertificate.org/).
8897beb0c9SEd Maste* Include `PR: \<bugnumber\>` if fixing a Bugzilla Problem Report.
8997beb0c9SEd Maste* Include the URL of a related code review, if applicable.
9097beb0c9SEd Maste  (Avoid opening both Phabricator/Differential reviews and GitHub Pull Requests
9197beb0c9SEd Maste  for the same change.)
9297beb0c9SEd Maste
9397beb0c9SEd Maste#### Author Information
9497beb0c9SEd Maste
9597beb0c9SEd Maste* Commits use your name and valid email address.
9697beb0c9SEd Maste* GitHub-generated `users.noreply.github.com` addresses cannot be used.
9797beb0c9SEd Maste* See [Author Name and Email](#author-name-and-email) for details.
9897beb0c9SEd Maste
9997beb0c9SEd Maste### Contributor Responsibilities
10097beb0c9SEd Maste
10197beb0c9SEd Maste* Monitor your Pull Request and respond to review feedback promptly.
10297beb0c9SEd Maste* Pull Requests may be closed if there is no response for **one month**.
10397beb0c9SEd Maste
10497beb0c9SEd Maste### Additional Requirements for FreeBSD Committers
10597beb0c9SEd Maste
10697beb0c9SEd Maste* Committers submitting Pull Requests are for pushing their changes to the tree
10797beb0c9SEd Maste  (including obtaining any required approvals).
10897beb0c9SEd Maste* Pull Requests opened by FreeBSD committers may be closed after one month
10997beb0c9SEd Maste  unless there is a strong reason to keep them open.
11097beb0c9SEd Maste
11197beb0c9SEd Maste### Quality Expectations
11297beb0c9SEd Maste
11397beb0c9SEd MasteLow quality submimssions will be rejected.  This includes submissions generated
11497beb0c9SEd Masteby AI tools that lack sufficient validation, testing, or understanding by the
11597beb0c9SEd Mastesubmitter.
11697beb0c9SEd Maste
11797beb0c9SEd MasteA pull request may be closed if there are too many obvious mistakes, or when a
11897beb0c9SEd Mastetime-consuming rework is needed.
11997beb0c9SEd Maste
12097beb0c9SEd MasteAutomated accounts or chatbots must not submit pull requests or use pull
12197beb0c9SEd Masterequest interactions to train AI or LLM systems.
12281ef45edSWarner Losh
1239c1335ceSWarner LoshFinally, if we close a pull request because it's not ready yet, or stalled out,
1249c1335ceSWarner Loshplease don't give up. You can resubmit them later once you have time to finish
1259c1335ceSWarner Loshthe work, or to have them reconsidered if you think we've made an error in
1269c1335ceSWarner Loshclosing it.
1279c1335ceSWarner Losh
128febba462SEd Maste### Author Name and Email
129febba462SEd Maste
130b2df9c07SWarner LoshPlease use a name and email address in the `Signed-off-by` trailer and as the
131b2df9c07SWarner Loshauthor of the git commits, since we cannot accept anonymous contributions. It is
132b2df9c07SWarner Loshcommon, but not required, to use some form of your full name. We realize that
133b2df9c07SWarner Loshsome contributors are not comfortable doing so or prefer to contribute under a
134b2df9c07SWarner Loshpseudonym, preferred name, chosen name or similar moniker that might not match
135b2df9c07SWarner Loshrelevant government records. We can accept your patch, as long as the name and
136b2df9c07SWarner Loshemail you use are distinctive, identifying, and not misleading. Please note that
137b2df9c07SWarner Loshif your patch is accepted, the name and email address will become a permanent
138b2df9c07SWarner Loshand immutable part of the public history of the FreeBSD source tree.
139b2df9c07SWarner Losh
140b2df9c07SWarner LoshThe goal of this policy is to allow us to have sufficient information to contact
141b2df9c07SWarner Loshyou if questions arise about your contribution. Addresses of the form
142b2df9c07SWarner Loshsomething@users.noreply.github.com do not meet this standard since we cannot use
143b2df9c07SWarner Loshit to contact you. We can use `.mailmap` for name or email changes and mistakes,
144b2df9c07SWarner Loshbut is imperfect.
145b2df9c07SWarner Losh
146b2df9c07SWarner LoshCore (core@freebsd.org) may request authors of significant changes using an
147b2df9c07SWarner Loshobvious pseudonym to document their identity more concretely should there be
148b2df9c07SWarner Loshissues in the future. The author may request this documentation be kept
149b2df9c07SWarner Loshconfidential unless needed for legal issues arising from their contributions.
150febba462SEd Maste
15181ef45edSWarner Losh## Style
15281ef45edSWarner Losh
15381ef45edSWarner LoshAvoid adding trailing newlines and whitespace. These slow down the integration
15481ef45edSWarner Loshprocess and are a distraction. `git diff` will highlight them in red, as will
15581ef45edSWarner Loshthe Files Changed tab in the pull request.
15681ef45edSWarner Losh
15781ef45edSWarner LoshFor C programs, see [style(9)](https://man.freebsd.org/cgi/man.cgi?query=style&sektion=9)
15881ef45edSWarner Loshfor details. You can use [Clang format](https://clang.llvm.org/docs/ClangFormat.html)
15981ef45edSWarner Loshwith the top level .clang-format file if you are unsure. The
16081ef45edSWarner Losh[git clang-format](https://github.com/llvm-mirror/clang/blob/master/tools/clang-format/git-clang-format)
16181ef45edSWarner Loshcommand can help minimize churn by only formatting the areas nearby the changes. While
16281ef45edSWarner Loshnot perfect, using these tools will maximize your chances of not having style
16381ef45edSWarner Loshcomments on your pull requests.
16481ef45edSWarner Losh
165467e3e2fSAlexander ZiaeeFor [Lua](https://www.lua.org), see
166467e3e2fSAlexander Ziaee[style.lua(9)](https://man.freebsd.org/cgi/man.cgi?query=style.lua&sektion=9)
167467e3e2fSAlexander Ziaeefor details. Lua is used for the boot loader and a few scripts in the base system.
168467e3e2fSAlexander Ziaee
16981ef45edSWarner LoshFor Makefiles changes, see
17081ef45edSWarner Losh[style.Makefile(5)](https://man.freebsd.org/cgi/man.cgi?query=style.Makefile&sektion=5)
17181ef45edSWarner Loshfor details. FreeBSD's base system uses the in-tree make, not GNU Make, so
17281ef45edSWarner Losh[make(1)](https://man.freebsd.org/cgi/man.cgi?query=make&sektion=1) is another useful
17381ef45edSWarner Loshresource.
17481ef45edSWarner Losh
175467e3e2fSAlexander ZiaeeFor manual page changes, see
176467e3e2fSAlexander Ziaee[style.mdoc(5)](https://man.freebsd.org/cgi/man.cgi?query=style.mdoc&sektion=5)
177467e3e2fSAlexander Ziaeefor details. Changes should pass `mandoc -Tlint` and igor (install the latter with `pkg install igor`).
178467e3e2fSAlexander ZiaeePlease be sure to observe the one-sentence-per-line rule so manual pages properly render.
179467e3e2fSAlexander ZiaeeProposed changes to manual pages should not bump the document date until merged.
18081ef45edSWarner Losh
18181ef45edSWarner LoshFor shell scripts, avoid using bash. The system shell (/bin/sh) is preferred.
18281ef45edSWarner LoshShell scripts in the base system cannot use bash or bash extensions
18381ef45edSWarner Loshnot present in FreeBSD's [shell](https://man.freebsd.org/cgi/man.cgi?query=sh&sektion=1).
18481ef45edSWarner Losh
18581ef45edSWarner Losh## Signed-off-by
18681ef45edSWarner Losh
187015ae668SWarner LoshOther projects mandate Signed-off-by to create a paper trail for contributions they
18881ef45edSWarner Loshreceive. The Developer Certificate of Origin is an attestation that the person
18981ef45edSWarner Loshmaking the contribution can do it under the current license of the file. Other
19081ef45edSWarner Loshprojects that have 'delegated' hierarchies also use it when maintainers
19181ef45edSWarner Loshintegrate these patches and submit them upstream.
19281ef45edSWarner Losh
19381ef45edSWarner LoshRight now, pull requests on GitHub are an experimental feature. We strongly
19481ef45edSWarner Loshsuggest that people add this line. It creates a paper trail for infrequent
19581ef45edSWarner Loshcontributors. Also, developers that are landing a pull request will use a
19681ef45edSWarner LoshSigned-off-by line to set the author for the commit.
19781ef45edSWarner Losh
19881ef45edSWarner LoshThese lines are easy to add with `git commit -s`.
199fb03f7f8SWarner Losh
200fb03f7f8SWarner Losh## Submitting as part of class work
201fb03f7f8SWarner Losh
202fb03f7f8SWarner LoshIf you are a professor or teacher that wishes to have your students submit fixes
203fb03f7f8SWarner Loshas part of their class work, please contact imp@FreeBSD.org before the semester
204fb03f7f8SWarner Loshto ensure we allocate the proper resources to process them quickly. We'll give
205fb03f7f8SWarner Loshyou more details when you contact us and thanks for including FreeBSD in your
206fb03f7f8SWarner Loshclass work. It also helps us keep track.
20705e5852dSWarner Losh
20805e5852dSWarner Losh## FreeBSD's Upstreams
20905e5852dSWarner Losh
210ede45635SEd MasteAnything that's in the directory `contrib`, `crypto`, `sys/contrib`,
211ede45635SEd Maste`sys/crypto/` or `sys/cddl` likely has an upstream we pull from. Please do a
212ede45635SEd Maste`git log --merges` in any subdirectory of these you are submitting patches for
213ede45635SEd Masteto find out the last time we merged from upstream. If it is in the last 5 years,
214ede45635SEd Masteupstream is "active" and you should submit your patches there and let the last
215ede45635SEd Mastefew people to commit to this file (especially merge commits) know. If it's been
216ede45635SEd Mastemore than 5 years, upstream is likely inactive so please submit the patch. We
217ede45635SEd Mastecan sort out if it should go into FreeBSD or upstream.
218