diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c235b432c8..8c1b3fb80f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The list of conflicted paths is printed whenever the working copy changes. This can be disabled with the `--quiet` option. +* There's a new `mine()` method on the commit type in templates + ### Fixed bugs ## [0.16.0] - 2024-04-03 diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index ca65f19b1b2..17c321f9682 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -458,6 +458,12 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm Ok(L::wrap_signature(out_property)) }, ); + map.insert("mine", |language, _build_ctx, self_property, function| { + template_parser::expect_no_arguments(function)?; + let user_email = language.revset_parse_context.user_email.clone(); + let out_property = self_property.map(move |commit| commit.author().email == user_email); + Ok(L::wrap_boolean(out_property)) + }); map.insert( "working_copies", |language, _build_ctx, self_property, function| { diff --git a/cli/tests/test_commit_template.rs b/cli/tests/test_commit_template.rs index 26111a3a2cf..0de96ad3981 100644 --- a/cli/tests/test_commit_template.rs +++ b/cli/tests/test_commit_template.rs @@ -146,6 +146,35 @@ fn test_log_author_timestamp_local() { "###); } +#[test] +fn test_mine_is_true_when_author_is_user() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + test_env.jj_cmd_ok( + &repo_path, + &[ + "--config-toml=user.email='johndoe@example.com'", + "--config-toml=user.name='John Doe'", + "new", + ], + ); + + let stdout = test_env.jj_cmd_success( + &repo_path, + &[ + "log", + "-T", + r#"if(mine, "mine", coalesce(author.email(), email_placeholder))"#, + ], + ); + insta::assert_snapshot!(stdout, @r###" + @ johndoe@example.com + ◉ mine + ◉ (no email set) + "###); +} + #[test] fn test_log_default() { let test_env = TestEnvironment::default(); diff --git a/docs/templates.md b/docs/templates.md index 9db50f62852..f6a33b64c33 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -72,6 +72,8 @@ This type cannot be printed. The following methods are defined. * `parents() -> List` * `author() -> Signature` * `committer() -> Signature` +* `mine() -> Boolean`: Commits where the author's email matches the email of the current + user. * `working_copies() -> String`: For multi-workspace repository, indicate working-copy commit as `@`. * `current_working_copy() -> Boolean`: True for the working-copy commit of the