ok/jj
1
0
Fork 0
forked from mirrors/jj

template: add method mine() to commit type

This commit is contained in:
Noah Mayr 2024-04-04 17:43:59 +02:00
parent 361b4ca425
commit 2cf1c34f58
4 changed files with 40 additions and 0 deletions

View file

@ -16,6 +16,9 @@ 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.
* Commit objects in templates now have a `mine() -> Boolean` method analog to the same function in revsets.
It evaluates to true if the email of the commit author matches the current `user.email`.
### Fixed bugs
## [0.16.0] - 2024-04-03

View file

@ -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| {

View file

@ -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#"coalesce(if(mine, "mine"), 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();

View file

@ -72,6 +72,8 @@ This type cannot be printed. The following methods are defined.
* `parents() -> List<Commit>`
* `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 `<workspace name>@`.
* `current_working_copy() -> Boolean`: True for the working-copy commit of the