Skip to content

Commit

Permalink
cli: oplog: add builtin_op_log_oneline template
Browse files Browse the repository at this point in the history
Motivation:
* one-line logs can be more readable and fit more content into the screen
* consistency with `jj log -T builtin_log_oneline`
  • Loading branch information
jakobhellermann committed Jan 9, 2025
1 parent 720c903 commit 80c4222
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* New `merge-tools.<TOOL>.diff-expected-exit-codes` config option to suppress
warnings from tools exiting with non-zero exit codes.

* Add a new template alias `builtin_op_log_oneline` along with `format_operation_oneline` and `format_snapshot_operation_oneline`

### Fixed bugs

* Fixed diff selection by external tools with `jj split`/`commit -i FILESETS`.
Expand Down
19 changes: 19 additions & 0 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ label(if(current_operation, "current_operation"),
)
'''
builtin_op_log_comfortable = 'builtin_op_log_compact ++ "\n"'
builtin_op_log_oneline = '''
label(if(current_operation, "current_operation"),
coalesce(
if(snapshot, format_snapshot_operation_oneline(self)),
if(root, format_root_operation(self)),
format_operation_oneline(self),
)
)
'''

description_placeholder = 'label("description placeholder", "(no description set)")'
email_placeholder = 'label("email placeholder", "(no email set)")'
Expand Down Expand Up @@ -237,6 +246,16 @@ if(ref.tracking_present(), surround("(", ")", separate(", ",
'format_snapshot_operation(op)' = 'format_operation(op)'
'format_root_operation(root)' = 'separate(" ", root.id().short(), label("root", "root()")) ++ "\n"'


'format_operation_oneline(op)' = '''
separate(" ",
op.id().short(), op.user(), format_time_range(op.time()),
op.description().first_line(),
if(op.tags(), op.tags()),
) ++ "\n"
'''
'format_snapshot_operation_oneline(op)' = 'format_operation_oneline(op)'

# We have "hidden" override "divergent", since a hidden revision does not cause
# change id conflicts and is not affected by such conflicts; you have to use the
# commit id to refer to a hidden revision regardless.
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/test_evolog_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn test_evolog_with_no_template() {
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_cli_error(&repo_path, &["evolog", "-T"]);
insta::assert_snapshot!(stderr, @r#"
insta::assert_snapshot!(stderr, @r"
error: a value is required for '--template <TEMPLATE>' but none was supplied
For more information, try '--help'.
Expand All @@ -342,11 +342,12 @@ fn test_evolog_with_no_template() {
- builtin_op_log_compact
- builtin_op_log_node
- builtin_op_log_node_ascii
- builtin_op_log_oneline
- commit_summary_separator
- description_placeholder
- email_placeholder
- name_placeholder
"#);
");
}

#[test]
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn test_log_with_no_template() {
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-T"]);
insta::assert_snapshot!(stderr, @r#"
insta::assert_snapshot!(stderr, @r"
error: a value is required for '--template <TEMPLATE>' but none was supplied
For more information, try '--help'.
Expand All @@ -52,11 +52,12 @@ fn test_log_with_no_template() {
- builtin_op_log_compact
- builtin_op_log_node
- builtin_op_log_node_ascii
- builtin_op_log_oneline
- commit_summary_separator
- description_placeholder
- email_placeholder
- name_placeholder
"#);
");
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions cli/tests/test_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn test_op_log_with_no_template() {
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_cli_error(&repo_path, &["op", "log", "-T"]);
insta::assert_snapshot!(stderr, @r#"
insta::assert_snapshot!(stderr, @r"
error: a value is required for '--template <TEMPLATE>' but none was supplied
For more information, try '--help'.
Expand All @@ -157,11 +157,12 @@ fn test_op_log_with_no_template() {
- builtin_op_log_compact
- builtin_op_log_node
- builtin_op_log_node_ascii
- builtin_op_log_oneline
- commit_summary_separator
- description_placeholder
- email_placeholder
- name_placeholder
"#);
");
}

#[test]
Expand Down Expand Up @@ -299,6 +300,13 @@ fn test_op_log_builtin_templates() {
[EOF]
"#);

insta::assert_snapshot!(render(r#"builtin_op_log_oneline"#), @r"
d009cfc04993 [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22 args: jj describe -m 'description 0'
eac759b9ab75 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
000000000000 root()
[EOF]
");
}

#[test]
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/test_show_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn test_show_with_no_template() {
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_cli_error(&repo_path, &["show", "-T"]);
insta::assert_snapshot!(stderr, @r#"
insta::assert_snapshot!(stderr, @r"
error: a value is required for '--template <TEMPLATE>' but none was supplied
For more information, try '--help'.
Expand All @@ -266,11 +266,12 @@ fn test_show_with_no_template() {
- builtin_op_log_compact
- builtin_op_log_node
- builtin_op_log_node_ascii
- builtin_op_log_oneline
- commit_summary_separator
- description_placeholder
- email_placeholder
- name_placeholder
"#);
");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn test_templater_parse_error() {
| ^-----^
|
= Keyword "builtin" doesn't exist
Hint: Did you mean "builtin_log_comfortable", "builtin_log_compact", "builtin_log_compact_full_description", "builtin_log_detailed", "builtin_log_node", "builtin_log_node_ascii", "builtin_log_oneline", "builtin_op_log_comfortable", "builtin_op_log_compact", "builtin_op_log_node", "builtin_op_log_node_ascii"?
Hint: Did you mean "builtin_log_comfortable", "builtin_log_compact", "builtin_log_compact_full_description", "builtin_log_detailed", "builtin_log_node", "builtin_log_node_ascii", "builtin_log_oneline", "builtin_op_log_comfortable", "builtin_op_log_compact", "builtin_op_log_node", "builtin_op_log_node_ascii", "builtin_op_log_oneline"?
"#);
}

Expand Down

0 comments on commit 80c4222

Please sign in to comment.