mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
template: add method mine() to commit type
This commit is contained in:
parent
361b4ca425
commit
2cf1c34f58
4 changed files with 40 additions and 0 deletions
|
@ -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.
|
* The list of conflicted paths is printed whenever the working copy changes.
|
||||||
This can be disabled with the `--quiet` option.
|
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
|
### Fixed bugs
|
||||||
|
|
||||||
## [0.16.0] - 2024-04-03
|
## [0.16.0] - 2024-04-03
|
||||||
|
|
|
@ -458,6 +458,12 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
|
||||||
Ok(L::wrap_signature(out_property))
|
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(
|
map.insert(
|
||||||
"working_copies",
|
"working_copies",
|
||||||
|language, _build_ctx, self_property, function| {
|
|language, _build_ctx, self_property, function| {
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn test_log_default() {
|
fn test_log_default() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
|
@ -72,6 +72,8 @@ This type cannot be printed. The following methods are defined.
|
||||||
* `parents() -> List<Commit>`
|
* `parents() -> List<Commit>`
|
||||||
* `author() -> Signature`
|
* `author() -> Signature`
|
||||||
* `committer() -> 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_copies() -> String`: For multi-workspace repository, indicate
|
||||||
working-copy commit as `<workspace name>@`.
|
working-copy commit as `<workspace name>@`.
|
||||||
* `current_working_copy() -> Boolean`: True for the working-copy commit of the
|
* `current_working_copy() -> Boolean`: True for the working-copy commit of the
|
||||||
|
|
Loading…
Reference in a new issue