jj / How jj version works

How jj version works

jj version prints the version string that was baked into the binary when it was compiled.

On this page
  1. 1. Command-line surface
  2. 3. End-to-end flow
  3. 4. Core architecture touchpoints
  4. Example output

In short: at build time, cli/build.rs sets JJ_VERSION to the crate version, plus the source commit's hash when it can find one. main hands that string to clap, and the command prints clap's rendering of it. Nothing is loaded and nothing is written.

The command is cmd_version, one line of work. Its help text: "Display version information" (source). It is the Version variant of the top-level Command enum (source, dispatch).

1. Command-line surface

It takes no arguments of its own: VersionArgs is empty (source). The same string is also available as clap's --version/-V flag, which upstream's test uses (test); those flags bypass the default command, like --help (source).

The global flags are on the CLI page.

3. End-to-end flow

jj version: from build to output At compile time, build.rs reads CARGO_PKG_VERSION and looks for a source hash, first in NIX_JJ_GIT_HASH, then from jj log of @-, then from git rev-parse HEAD, and sets JJ_VERSION to the version, followed by a dash and the hash if one was found. At run time, main passes JJ_VERSION to CliRunner::version, which sets it on the clap command. cmd_version writes the command's render_version to stdout. compile time build.rs: JJ_VERSION = CARGO_PKG_VERSION [ "-" hash ] hash from $NIX_JJ_GIT_HASH, else jj log -r=@- commit_id, else git rev-parse HEAD run time main: CliRunner::init() .version(env!("JJ_VERSION")) CliRunner::version sets the clap Command's version cmd_version write render_version() to stdout

4. Core architecture touchpoints

PieceRole here
cli/build.rsComputes JJ_VERSION. When jj is built from a merge commit, the jj lookup returns several hashes joined by - (source); upstream's test deliberately fails on that form so it isn't released (test).
CliRunner::versionThe hook a custom jj binary uses to set its own version string.
Repo, working copy, operation logNot touched: cmd_version never asks for a workspace (source).

Example output

Upstream's test accepts exactly two shapes once hex digits are masked, a release build and a build with a 40-character hash (source):

jj ?.??.?
jj ?.??.?-????????????????????????????????????????