Skip to content

Commit

Permalink
cli: fix highlighting of checkout commit in "log --no-graph"
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Jan 11, 2023
1 parent fb6181f commit ba70167
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [1;[email protected] 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
description 1
9a45c67d3e96 [[email protected] 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]
Expand Down

0 comments on commit ba70167

Please sign in to comment.