diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e85c2753..115f7e506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Use `if(description, description, "(no description set)\n")` to get back the previous behavior. +* If a custom `template.log.graph` template is set, working-copy commit will + no longer be highlighted automatically. Wrap your template with + `label(if(current_working_copy, "working_copy"), ...)` to label the + working-copy entry. + * The global `--no-commit-working-copy` is now called `--ignore-working-copy`. ### New features diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 457580577..00e4b7ee3 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1407,21 +1407,23 @@ fn log_template(settings: &UserSettings) -> String { }; let default_template = format!( r#" - if(divergent, - label("divergent", change_id.{prefix_format} "??"), - change_id.{prefix_format}) - " " author.email() - " " {committer_timestamp} - if(branches, " " branches) - if(tags, " " tags) - if(working_copies, " " working_copies) - if(git_head, " " git_head) - " " commit_id.{prefix_format} - if(conflict, label("conflict", " conflict")) - "\n" - if(empty, label("empty", "(empty) ")) - if(description, description.first_line(), {DESCRIPTION_PLACEHOLDER_TEMPLATE}) - "\n""#, + label(if(current_working_copy, "working_copy"), + if(divergent, + label("divergent", change_id.{prefix_format} "??"), + change_id.{prefix_format}) + " " author.email() + " " {committer_timestamp} + if(branches, " " branches) + if(tags, " " tags) + if(working_copies, " " working_copies) + if(git_head, " " git_head) + " " commit_id.{prefix_format} + if(conflict, label("conflict", " conflict")) + "\n" + if(empty, label("empty", "(empty) ")) + if(description, description.first_line(), {DESCRIPTION_PLACEHOLDER_TEMPLATE}) + "\n" + )"#, ); settings .config() @@ -1459,15 +1461,6 @@ 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| { - if Some(commit.id()) == wc_commit_id { - formatter.with_label("working_copy", |formatter| { - template.format(commit, formatter) - }) - } else { - template.format(commit, formatter) - } - }; { ui.request_pager(); @@ -1509,7 +1502,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C let mut buffer = vec![]; let commit_id = index_entry.commit_id(); let commit = store.get_commit(&commit_id)?; - format_commit_template(&commit, ui.new_formatter(&mut buffer).as_mut())?; + template.format(&commit, ui.new_formatter(&mut buffer).as_mut())?; if !buffer.ends_with(b"\n") { buffer.push(b'\n'); } @@ -1544,7 +1537,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())?; - format_commit_template(&commit, formatter)?; + template.format(&commit, formatter)?; if !diff_formats.is_empty() { diff_util::show_patch( formatter, diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index e772f5c4d..f9b4de5e9 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -182,7 +182,7 @@ fn test_color_config() { // Test that --color=always is respected. let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]); insta::assert_snapshot!(stdout, @r###" - @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 + @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 o 0000000000000000000000000000000000000000 "###); @@ -190,7 +190,7 @@ fn test_color_config() { test_env.add_config(r#"ui.color="always""#); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]); insta::assert_snapshot!(stdout, @r###" - @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 + @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 o 0000000000000000000000000000000000000000 "###); @@ -246,7 +246,7 @@ fn test_color_config() { test_env.add_env_var("NO_COLOR", ""); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]); insta::assert_snapshot!(stdout, @r###" - @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 + @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 o 0000000000000000000000000000000000000000 "###); diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index 609546ce8..5cae92895 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -659,7 +659,8 @@ fn test_graph_template_color() { ); // First test without color for comparison - let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T=description"]); + let template = r#"label(if(current_working_copy, "working_copy"), description)"#; + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(stdout, @r###" @ single line o first line @@ -667,7 +668,7 @@ fn test_graph_template_color() { | third line o "###); - let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T=description"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", template]); insta::assert_snapshot!(stdout, @r###" @ single line o first line