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
4. Core architecture touchpoints
| Piece | Role here |
|---|---|
cli/build.rs | Computes 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::version | The hook a custom jj binary uses to set its own version string. |
| Repo, working copy, operation log | Not 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 ?.??.?-????????????????????????????????????????