cli: fix highlighting of checkout commit in "log --no-graph"

This commit is contained in:
Yuya Nishihara 2023-01-11 09:42:03 +09:00
parent fb6181f212
commit ba7016788f
2 changed files with 23 additions and 11 deletions

View file

@ -1609,6 +1609,16 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
&workspace_id,
&template_string,
);
let format_commit_template = |commit: &Commit, formatter: &mut dyn Formatter| {
let is_checkout = Some(commit.id()) == checkout_id;
if is_checkout {
formatter.with_label("working_copy", |formatter| {
template.format(commit, formatter)
})
} else {
template.format(commit, formatter)
}
};
{
ui.request_pager();
@ -1652,16 +1662,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let commit_id = index_entry.commit_id();
let commit = store.get_commit(&commit_id)?;
let is_checkout = Some(&commit_id) == checkout_id;
{
let mut formatter = ui.new_formatter(&mut buffer);
if is_checkout {
formatter.with_label("working_copy", |formatter| {
template.format(&commit, formatter)
})?;
} else {
template.format(&commit, formatter.as_mut())?;
}
}
format_commit_template(&commit, ui.new_formatter(&mut buffer).as_mut())?;
if !buffer.ends_with(b"\n") {
buffer.push(b'\n');
}
@ -1691,7 +1692,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
};
for index_entry in iter {
let commit = store.get_commit(&index_entry.commit_id())?;
template.format(&commit, formatter)?;
format_commit_template(&commit, formatter)?;
if !diff_formats.is_empty() {
diff_util::show_patch(
formatter,

View file

@ -82,6 +82,17 @@ fn test_log_default() {
o 000000000000  1970-01-01 00:00:00.000 +00:00 000000000000
(no description set)
"###);
// Color without graph
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"
ffdaa62087a2 test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
description 1
9a45c67d3e96 test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264ae97
add a file
000000000000  1970-01-01 00:00:00.000 +00:00 000000000000
(no description set)
"###);
}
#[test]