templates: allow using string in if-condition; use in default template

Given how easy this was, I can't believe I didn't make the change
sooner.

I haven't updated the screenshots in the readme because I plan to make
some further changes to the default template. I'll update them after
those changes.
This commit is contained in:
Martin von Zweigbergk 2022-11-13 11:19:56 -08:00 committed by Martin von Zweigbergk
parent 43cfb98f78
commit 4ec2092e57
6 changed files with 37 additions and 33 deletions

View file

@ -155,7 +155,7 @@ $ jj log -r '@ | root | branches()'
: (no description set)
o 080a9b37ff7e 6a91b4ba16c7 martinvonz@google.com 2021-05-23 22:08:37.000 -07:00 main
: cli: make `jj st` show parent commit before working copy commit
o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00
o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00
```
(The `000000000000` commit is a virtual commit that's called the "root commit".
@ -201,9 +201,9 @@ Rebased 2 commits
Working copy now at: 9195b6d2e8dc C
Added 0 files, modified 1 files, removed 0 files
$ jj log
@ 66274d5a7d2d 8e6178b84ffb martinvonz@google.com 2021-05-26 12:39:35.000 -07:00 conflict
@ 66274d5a7d2d 8e6178b84ffb martinvonz@google.com 2021-05-26 12:39:35.000 -07:00 conflict
| C
o 0c305a9e6b27 5548374c0794 martinvonz@google.com 2021-05-26 12:39:30.000 -07:00 conflict
o 0c305a9e6b27 5548374c0794 martinvonz@google.com 2021-05-26 12:39:30.000 -07:00 conflict
| B2
| o 47e336632333 ce619d39bd96 martinvonz@google.com 2021-05-26 12:39:20.000 -07:00
|/ B1
@ -293,9 +293,9 @@ Working copy now at: 41f0d2289b56
$ jj log
@ 41f0d2289b56 b1e3a4afde5e martinvonz@google.com 2021-05-26 12:52:39.000 -07:00
|
| o 66274d5a7d2d 8e6178b84ffb martinvonz@google.com 2021-05-26 12:39:35.000 -07:00 conflict
| o 66274d5a7d2d 8e6178b84ffb martinvonz@google.com 2021-05-26 12:39:35.000 -07:00 conflict
|/ C
o 0c305a9e6b27 5548374c0794 martinvonz@google.com 2021-05-26 12:39:30.000 -07:00 conflict
o 0c305a9e6b27 5548374c0794 martinvonz@google.com 2021-05-26 12:39:30.000 -07:00 conflict
| B2
| o 47e336632333 ce619d39bd96 martinvonz@google.com 2021-05-26 12:39:20.000 -07:00
|/ B1

View file

@ -1998,9 +1998,9 @@ fn log_template(settings: &UserSettings) -> String {
" " change_id.short()
" " author.email()
" " label("timestamp", author.timestamp())
" " branches
" " tags
" " working_copies
if(branches, " " branches)
if(tags, " " tags)
if(working_copies, " " working_copies)
if(is_git_head, label("git_head", " HEAD@git"))
if(divergent, label("divergent", " divergent"))
if(conflict, label("conflict", " conflict"))

View file

@ -289,6 +289,10 @@ fn parse_boolean_commit_property<'a>(
match pair.as_rule() {
Rule::identifier => match parse_commit_keyword(repo, workspace_id, pair.clone()).0 {
Property::Boolean(property) => property,
Property::String(property) => Box::new(TemplateFunction::new(
property,
Box::new(|string| !string.is_empty()),
)),
_ => panic!("cannot yet use this as boolean: {:?}", pair),
},
_ => panic!("cannot yet use this as boolean: {:?}", pair),

View file

@ -64,7 +64,7 @@ fn test_alias_cannot_override_builtin() {
// Alias should be ignored
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]);
insta::assert_snapshot!(stdout, @r###"
o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00
o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00
(no description set)
"###);
}

View file

@ -107,7 +107,7 @@ fn test_init_git_external() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o 8d698d4a8ee1 d3866db7e30a git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git
o 8d698d4a8ee1 d3866db7e30a git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git
~ My commit message
"###);
}
@ -150,7 +150,7 @@ fn test_init_git_colocated() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o 8d698d4a8ee1 d3866db7e30a git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git
o 8d698d4a8ee1 d3866db7e30a git.user@example.com 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git
~ My commit message
"###);
}

View file

@ -34,13 +34,13 @@ fn test_obslog_with_or_without_diff() {
let stdout = get_log_output(&test_env, &repo_path, &["obslog"]);
insta::assert_snapshot!(stdout, @r###"
@ 1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
@ 1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
| my description
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
| my description
o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
| my description
o c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
o c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
"###);
@ -48,43 +48,43 @@ fn test_obslog_with_or_without_diff() {
// (even even though it resulted in a conflict).
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "-p"]);
insta::assert_snapshot!(stdout, @r###"
@ 1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
@ 1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
| my description
| Resolved conflict in file1:
| 1 1: <<<<<<<resolved
| 2 : %%%%%%%
| 3 : +bar
| 4 : >>>>>>>
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
| my description
o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
| my description
| Modified regular file file1:
| 1 1: foo
| 2: bar
| Added regular file file2:
| 1: foo
o c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
o c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
"###);
// Test `--no-graph`
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"
1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
my description
8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
"###);
// Test `--git` format, and that it implies `-p`
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "--no-graph", "--git"]);
insta::assert_snapshot!(stdout, @r###"
1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
1daafc17fefb test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
diff --git a/file1 b/file1
index e155302a24...2ab19ae607 100644
@ -96,9 +96,9 @@ fn test_obslog_with_or_without_diff() {
-+bar
->>>>>>>
+resolved
813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
my description
8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
diff --git a/file1 b/file1
index 257cc5642c...3bd1f0e297 100644
@ -114,7 +114,7 @@ fn test_obslog_with_or_without_diff() {
+++ b/file2
@@ -1,0 +1,1 @@
+foo
c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
c8ceb219336b test.user@example.com 2001-02-03 04:05:08.000 +07:00
my description
"###);
}
@ -136,25 +136,25 @@ fn test_obslog_squash() {
let stdout = get_log_output(&test_env, &repo_path, &["obslog", "-p", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
o 9b6d4a272a6a test.user@example.com 2001-02-03 04:05:07.000 +07:00
o 9b6d4a272a6a test.user@example.com 2001-02-03 04:05:07.000 +07:00
|\ squashed
| | Modified regular file file1:
| | 1 1: foo
| | 2: bar
o | 803a7299cb1a test.user@example.com 2001-02-03 04:05:07.000 +07:00
o | 803a7299cb1a test.user@example.com 2001-02-03 04:05:07.000 +07:00
| | first
| | Added regular file file1:
| | 1: foo
o | 85a1e2839620 test.user@example.com 2001-02-03 04:05:07.000 +07:00
o | 85a1e2839620 test.user@example.com 2001-02-03 04:05:07.000 +07:00
| | first
o | 230dd059e1b0 test.user@example.com 2001-02-03 04:05:07.000 +07:00
o | 230dd059e1b0 test.user@example.com 2001-02-03 04:05:07.000 +07:00
/ (no description set)
o 69231a40d60d test.user@example.com 2001-02-03 04:05:09.000 +07:00
o 69231a40d60d test.user@example.com 2001-02-03 04:05:09.000 +07:00
| second
| Modified regular file file1:
| 1 1: foo
| 2: bar
o b567edda97ab test.user@example.com 2001-02-03 04:05:09.000 +07:00
o b567edda97ab test.user@example.com 2001-02-03 04:05:09.000 +07:00
second
"###);
}