diff --git a/src/commands.rs b/src/commands.rs index 0a304d0d3..c78024ed8 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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, diff --git a/tests/test_commit_template.rs b/tests/test_commit_template.rs index 5d40e1c50..da248c965 100644 --- a/tests/test_commit_template.rs +++ b/tests/test_commit_template.rs @@ -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]