This makes mkdocs compile cleanly
8.6 KiB
How to Contribute
Policies
We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
Contributor License Agreement
Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.
You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again.
Code reviews
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
Unlike many GitHub projects (but like many VCS projects), we care more about the contents of commits than about the contents of PRs. We review each commit separately, and we don't squash them when the PR is ready.
Each commit should ideally do one thing. For example, if you need to refactor a
function in order to add a new feature cleanly, put the refactoring in one
commit and the new feature in a different commit. If the refactoring itself
consists of many parts, try to separate out those into separate commits. You can
use jj split
to do it if you didn't realize ahead of time how it should be
split up. Include tests and documentation in the same commit as the code the
test and document. The commit message should describe the changes in the commit;
the PR description can even be empty, but feel free to include a personal
message.
When you address comments on a PR, don't make the changes in a commit on top (as
is typical on GitHub). Instead, please make the changes in the appropriate
commit. You can do that by checking out the commit (jj checkout/new <commit>
)
and then squash in the changes when you're done (jj squash
). jj git push
will automatically force-push the branch.
When your first PR has been approved, we typically give you contributor access, so you can address any remaining minor comments and then merge the PR yourself when you're ready. If you realize that some comments require non-trivial changes, please ask your reviewer to take another look.
Community Guidelines
This project follows Google's Open Source Community Guidelines.
Learning Rust
In addition to the Rust Book and the other excellent resources at https://www.rust-lang.org/learn, we recommend the "Comprehensive Rust" mini-course for an overview, especially if you are familiar with C++.
Setting up a development environment
To develop jj
, the mandatory steps are simply
to install Rust (the default
installer options are fine), clone the repository, and use cargo build
, cargo fmt
,
cargo clippy --workspace --all-targets
, and
cargo test --workspace
. If you are preparing a PR, there are some additional
recommended steps.
Summary
One-time setup:
rustup toolchain add nightly # wanted for 'rustfmt'
rustup toolchain add 1.71 # also specified in Cargo.toml
cargo install cargo-insta
cargo install cargo-watch
cargo install cargo-nextest
During development (adapt according to your preference):
cargo watch --ignore '.jj/**' -s \
'cargo clippy --workspace --all-targets \
&& cargo +1.71 check --workspace --all-targets'
cargo +nightly fmt # Occasionally
cargo nextest run --workspace # Occasionally
cargo insta test --workspace --test-runner nextest # Occasionally
WARNING: Build artifacts from debug builds and especially from repeated
invocations of cargo test
can quickly take up 10s of GB of disk space.
Cargo will happily use up your entire hard drive. If this happens, run
cargo clean
.
Explanation
These are listed roughly in order of decreasing importance.
-
Nearly any change to
jj
's CLI will require writing or updating snapshot tests that use theinsta
crate. To make this convenient, install thecargo-insta
binary. Usecargo insta test --workspace
to run tests, andcargo insta review --workspace
to update the snapshot tests. The--workspace
flag is needed to run the tests on all crates; by default, only the crate in the current directory is tested. -
Github CI checks require that the code is formatted with the nightly version of
rustfmt
. To do this on your computer, install the nightly toolchain and usecargo +nightly fmt
. -
Your code will be rejected if it cannot be compiled with the minimal supported version of Rust ("MSRV"). Currently,
jj
follows a rather casual MSRV policy: "The currentrustc
stable version, minus one." As of this writing, that version is 1.71.0. -
Your code needs to pass
cargo clippy
. You can also usecargo +nightly clippy
if you wish to see more warnings. -
You may also want to install and use
cargo-watch
. In this case, you should exclude.jj
. directory from the filesystem watcher, as it gets updated on everyjj log
. -
To run tests more quickly, use
cargo nextest run --workspace
. To usenextest
withinsta
, usecargo insta test --workspace --test-runner nextest
.
Previewing the HTML documentation
Setting up the prerequisites
To build the website, you must have Python and poetry
installed. If
your distribution packages poetry
, something like apt install python3-poetry
is likely the best way to install it. Otherwise, you
can download Python from https://python.org or follow the Python
installation instructions. Finally, follow the Poetry installation
instructions.
Once you have poetry
installed, you should ask it to install the rest
of the required tools into a virtual environment as follows:
poetry install
If you get requests to "unlock a keyring" or error messages about failing to do
so, this is a known poetry
bug. The workaround is to
run the following and then to try poetry install
again:
# For sh-compatible shells or recent versions of `fish`
export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring
Building the HTML docs locally (with live reload)
The HTML docs are built with MkDocs. After following the above steps, you should be able to view the docs by running
# Note: this and all the commands below should be run from the root of
# the `jj` source tree.
poetry run -- mkdocs serve
and opening http://127.0.0.1:8000 in your browser.
As you edit the md
files, the website should be rebuilt and reloaded in your
browser automatically, unless build errors occur.
You should occasionally check the terminal from which you ran mkdocs serve
for
any build errors or warnings. Warnings about "GET /versions.json HTTP/1.1" code 404
are expected and harmless.
Modifying protobuffers (this is not common)
Occasionally, you may need to change the .proto
files that define jj's data
storage format. In this case, you will need to add a few steps to the above
workflow.
- Install the
protoc
compiler. This usually means eitherapt-get install protobuf-compiler
or downloading an official release. Theprost
library docs have additional advice. - Run
cargo run -p gen-protos
regularly (or after every edit to a.proto
file). This is the same as runningcargo run
fromlib/gen-protos
. Thegen-protos
binary will use theprost-build
library to compile the.proto
files into.rs
files. - If you are adding a new
.proto
file, you will need to edit the list of these files inlib/gen-protos/src/main.rs
.
The .rs
files generated from .proto
files are included in the repository,
and there is a Github CI check that will complain if they do not match.