Skip to content

Commit

Permalink
cli: show commit summary in "tag list"
Browse files Browse the repository at this point in the history
This is basically a template version of print_branch_target().
  • Loading branch information
yuja committed Apr 29, 2024
1 parent 1568e03 commit 16d2a3e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Commit objects in templates now have a `contained_in(revset: String) ->
Boolean` method.

* `jj tag list` now prints commit summary along with the tag name.

### Fixed bugs

* Revsets now support `\`-escapes in string literal.
Expand Down
13 changes: 12 additions & 1 deletion cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ op_log = 'builtin_op_log_compact'
show = 'builtin_log_detailed'

tag_list = '''
label("tag", name) ++ "\n"
label("tag", name) ++ format_ref_targets(self) ++ "\n"
'''

[template-aliases]
Expand Down Expand Up @@ -147,6 +147,17 @@ separate(" ",
) ++ "\n"
'''

'format_ref_targets(ref)' = '''
if(ref.conflict(),
separate("\n",
" " ++ label("conflict", "(conflicted)") ++ ":",
ref.removed_targets().map(|c| " - " ++ format_commit_summary_with_refs(c, "")).join("\n"),
ref.added_targets().map(|c| " + " ++ format_commit_summary_with_refs(c, "")).join("\n"),
),
": " ++ format_commit_summary_with_refs(ref.normal_target(), ""),
)
'''

'format_operation(op)' = '''
concat(
separate(" ", op.id().short(), op.user(), format_time_range(op.time())), "\n",
Expand Down
22 changes: 14 additions & 8 deletions cli/tests/test_tag_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,36 @@ fn test_tag_list() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["tag", "list"]),
@r###"
conflicted_tag
test_tag
test_tag2
conflicted_tag (conflicted):
- rlvkpnrz caf975d0 (empty) commit1
+ zsuskuln 3db783e0 (empty) commit2
+ royxmykx 68d950ce (empty) commit3
test_tag: rlvkpnrz caf975d0 (empty) commit1
test_tag2: zsuskuln 3db783e0 (empty) commit2
"###);

insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["tag", "list", "--color=always"]),
@r###"
conflicted_tag
test_tag
test_tag2
conflicted_tag (conflicted):
- rlvkpnrz caf975d0 (empty) commit1
+ zsuskuln 3db783e0 (empty) commit2
+ royxmykx 68d950ce (empty) commit3
test_tag: rlvkpnrz caf975d0 (empty) commit1
test_tag2: zsuskuln 3db783e0 (empty) commit2
"###);

// Test pattern matching.
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["tag", "list", "test_tag2"]),
@r###"
test_tag2
test_tag2: zsuskuln 3db783e0 (empty) commit2
"###);

insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["tag", "list", "glob:test_tag?"]),
@r###"
test_tag2
test_tag2: zsuskuln 3db783e0 (empty) commit2
"###);

let template = r#"
Expand Down

0 comments on commit 16d2a3e

Please sign in to comment.