templates: Fix bug where operation summary was printed w/o color

This commit is contained in:
Ilya Grigoriev 2024-10-06 20:00:49 -07:00
parent f9d9c9c224
commit 7051effa8f
3 changed files with 16 additions and 13 deletions

View file

@ -1492,6 +1492,12 @@ impl WorkspaceCommandHelper {
&self.op_summary_template_text,
OperationTemplateLanguage::wrap_operation,
)
// TODO: "op_log" is not a great label name for op_summary. We could
// replace it with `operation summary` and use `operation` in
// colors.toml. TODO: It would be better to put labels like these
// consistently in the same place, e.g. `templates.toml` instead of the
// rust code.
.labeled("op_log")
}
pub fn short_change_id_template(&self) -> TemplateRenderer<'_, Commit> {

View file

@ -125,14 +125,12 @@ pub fn cmd_op_diff(
let op_summary_template = workspace_command.operation_summary_template();
ui.request_pager();
let mut formatter = ui.stdout_formatter();
formatter.with_label("op_log", |formatter| {
write!(formatter, "From operation ")?;
op_summary_template.format(&from_op, &mut *formatter)?;
writeln!(formatter)?;
write!(formatter, " To operation ")?;
op_summary_template.format(&to_op, &mut *formatter)?;
writeln!(formatter)
})?;
write!(formatter, "From operation ")?;
op_summary_template.format(&from_op, &mut *formatter)?;
writeln!(formatter)?;
write!(formatter, " To operation ")?;
op_summary_template.format(&to_op, &mut *formatter)?;
writeln!(formatter)?;
show_op_diff(
ui,

View file

@ -791,9 +791,8 @@ fn test_op_summary_diff_template() {
test_env.jj_cmd_ok(&repo_path, &["new", "--no-edit", "-m=scratch"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "undo", "--color=always"]);
insta::assert_snapshot!(&stdout, @"");
// BUG!! (Fixed in next commit)
insta::assert_snapshot!(&stderr, @r#"
Undid operation ac20a4ff4791 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 new empty commit
Undid operation ac20a4ff4791 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 new empty commit
"#);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -821,7 +820,7 @@ fn test_op_summary_diff_template() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "undo", "--color=debug"]);
insta::assert_snapshot!(&stdout, @"");
insta::assert_snapshot!(&stderr, @r#"
Undid operation <<id short::2301f6e6ec31>> <<time start::2001-02-03 04:05:11.000 +07:00>> - <<time end::2001-02-03 04:05:11.000 +07:00>> <<description first_line::new empty commit>>
Undid operation <<op_log id short::2301f6e6ec31>><<op_log:: >><<op_log time start::2001-02-03 04:05:11.000 +07:00>><<op_log:: - >><<op_log time end::2001-02-03 04:05:11.000 +07:00>><<op_log:: >><<op_log description first_line::new empty commit>>
"#);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -836,8 +835,8 @@ fn test_op_summary_diff_template() {
],
);
insta::assert_snapshot!(&stdout, @r#"
<<op_log::From operation >><<op_log id short::000000000000>><<op_log:: >><<op_log root::root()>><<op_log::>>
<<op_log:: To operation >><<op_log id short::d208ae1b4e3c>><<op_log:: >><<op_log time start::2001-02-03 04:05:12.000 +07:00>><<op_log:: - >><<op_log time end::2001-02-03 04:05:12.000 +07:00>><<op_log:: >><<op_log description first_line::undo operation 2301f6e6ec31931a9b0a594742d6035a44c05250d1707f7f8678e888b11a98773ef07bf0e8008a5bccddf7114da4a35d1a1b1f7efa37c1e6c80d6bdb8f0d7a90>><<op_log::>>
From operation <<op_log id short::000000000000>><<op_log:: >><<op_log root::root()>>
To operation <<op_log id short::d208ae1b4e3c>><<op_log:: >><<op_log time start::2001-02-03 04:05:12.000 +07:00>><<op_log:: - >><<op_log time end::2001-02-03 04:05:12.000 +07:00>><<op_log:: >><<op_log description first_line::undo operation 2301f6e6ec31931a9b0a594742d6035a44c05250d1707f7f8678e888b11a98773ef07bf0e8008a5bccddf7114da4a35d1a1b1f7efa37c1e6c80d6bdb8f0d7a90>>
Changed commits:
Change qpvuntsmwlqt