mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-30 08:05:05 +00:00
cli: fix highlighting of checkout commit in "log --no-graph"
This commit is contained in:
parent
fb6181f212
commit
ba7016788f
2 changed files with 23 additions and 11 deletions
|
@ -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,
|
||||
|
|
|
@ -82,6 +82,17 @@ fn test_log_default() {
|
|||
o [35m000000000000[0m [33m[0m [36m1970-01-01 00:00:00.000 +00:00[0m [34m000000000000[0m
|
||||
(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###"
|
||||
[1;35mffdaa62087a2[0m [1;33mtest.user@example.com[0m [1;36m2001-02-03 04:05:09.000 +07:00[0m [1;35mmy-branch[0m [1;34m9de54178d59d[0m
|
||||
[1;37mdescription 1[0m
|
||||
[35m9a45c67d3e96[0m [33mtest.user@example.com[0m [36m2001-02-03 04:05:08.000 +07:00[0m [34m4291e264ae97[0m
|
||||
add a file
|
||||
[35m000000000000[0m [33m[0m [36m1970-01-01 00:00:00.000 +00:00[0m [34m000000000000[0m
|
||||
(no description set)
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue