Skip to content

Commit

Permalink
cli: make jj show accept a template
Browse files Browse the repository at this point in the history
  • Loading branch information
zummenix committed Feb 10, 2024
1 parent 9171097 commit c9750fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Templates now support logical operators: `||`, `&&`, `!`

* `jj show` now accepts `-T`/`--template` option to render a description using
template

### Fixed bugs

* On Windows, symlinks in the repo are now materialized as regular files in the
Expand Down
10 changes: 9 additions & 1 deletion cli/src/commands/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub(crate) struct ShowArgs {
/// Ignored (but lets you pass `-r` for consistency with other commands)
#[arg(short = 'r', hide = true)]
unused_revision: bool,
/// Render description of a revision using the given template
///
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
#[arg(long, short = 'T')]
template: Option<String>,
#[command(flatten)]
format: DiffFormatArgs,
}
Expand All @@ -40,7 +45,10 @@ pub(crate) fn cmd_show(
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision, ui)?;
let template_string = command.settings().config().get_string("templates.show")?;
let template_string = match &args.template {
Some(value) => value.to_string(),
None => command.settings().config().get_string("templates.show")?,
};
let template = workspace_command.parse_commit_template(&template_string)?;
let diff_formats = diff_util::diff_formats_for(command.settings(), &args.format)?;
ui.request_pager();
Expand Down
1 change: 1 addition & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ Show commit description and changes in a revision
Possible values: `true`, `false`
* `-T`, `--template <TEMPLATE>` — Render description of a revision using the given template
* `-s`, `--summary` — For each path, show only whether it was modified, added, or deleted
Possible values: `true`, `false`
Expand Down
14 changes: 14 additions & 0 deletions cli/tests/test_show_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ fn test_show() {
"###);
}

#[test]
fn test_show_with_template() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["show", "-T", "description"]);

insta::assert_snapshot!(stdout, @r###"
a new commit
"###);
}

#[test]
fn test_show_relative_timestamps() {
let test_env = TestEnvironment::default();
Expand Down

0 comments on commit c9750fa

Please sign in to comment.