// Copyright 2022 The Jujutsu Authors//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License. use crate::common::TestEnvironment;use crate::common::to_toml_value; #[test]fn test_log_with_empty_revision() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["log", "-r="]); insta::assert_snapshot!(output, @" ------- stderr ------- error: a value is required for '--revision <REVSETS>' but none was supplied For more information, try '--help'. [EOF] [exit status: 2] ");} #[test]fn test_log_with_no_template() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["log", "-T"]); insta::assert_snapshot!(output, @" ------- stderr ------- error: a value is required for '--template <TEMPLATE>' but none was supplied For more information, try '--help'. Hint: The following template aliases are defined: - builtin_config_list - builtin_config_list_detailed - builtin_draft_commit_description - builtin_draft_commit_description_with_diff - builtin_evolog_compact - builtin_log_comfortable - builtin_log_compact - builtin_log_compact_full_description - builtin_log_detailed - builtin_log_node - builtin_log_node_ascii - builtin_log_oneline - builtin_log_redacted - builtin_op_log_comfortable - builtin_op_log_compact - builtin_op_log_node - builtin_op_log_node_ascii - builtin_op_log_oneline - builtin_op_log_redacted - builtin_workspace_list - commit_summary_separator - default_commit_description - description_placeholder - email_placeholder - empty_commit_marker - git_format_patch_email_headers - name_placeholder [EOF] [exit status: 2] ");} #[test]fn test_log_with_diff_stats() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\nfoo\n"); work_dir.write_file("file3", "foo\n"); work_dir.write_file("file4", "foo\n"); work_dir.write_file("file5", "foobar\nbaz\n"); work_dir .run_jj(["describe", "-m", "initial commit"]) .success(); work_dir.run_jj(["new", "-m", "multiple changes"]).success(); work_dir.write_file("file1", "foo\nbar\n"); work_dir.write_file("file2", "bar\n"); work_dir.write_file("file3", "baz\n"); work_dir.remove_file("file4"); work_dir.remove_file("file5"); work_dir.write_file("file6", "foobar\nbaz\n"); let template = r#" self.diff().files().map( |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.source().path() ++ " " ++ f.target().path() ).join("\n") ++ "\n" ++ self.diff().stat().files().map( |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.lines_added() ++ " " ++ f.lines_removed() ++ " " ++ f.path() ).join("\n") "#; let output = work_dir.run_jj(["log", "-T", template]); insta::assert_snapshot!(output, @" @ M modified file1 file1 │ M modified file2 file2 │ M modified file3 file3 │ D removed file4 file4 │ R renamed file5 file6 │ M modified 1 0 file1 │ M modified 0 1 file2 │ M modified 1 1 file3 │ D removed 0 1 file4 │ R renamed 0 0 file6 ○ A added file1 file1 │ A added file2 file2 │ A added file3 file3 │ A added file4 file4 │ A added file5 file5 │ A added 1 0 file1 │ A added 2 0 file2 │ A added 1 0 file3 │ A added 1 0 file4 │ A added 2 0 file5 ◆ [EOF] ");} #[test]fn test_log_with_or_without_diff() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.run_jj(["describe", "-m", "add a file"]).success(); work_dir.run_jj(["new", "-m", "a new commit"]).success(); work_dir.write_file("file1", "foo\nbar\n"); let output = work_dir.run_jj(["log", "-T", "description"]); insta::assert_snapshot!(output, @" @ a new commit ○ add a file ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "-p"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ Added regular file file1: │ 1: foo ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "--no-graph"]); insta::assert_snapshot!(output, @" a new commit add a file [EOF] "); // `-G` is the short name of --no-graph let output = work_dir.run_jj(["log", "-T", r#"commit_id.short() ++ "\n""#, "-G"]); insta::assert_snapshot!(output, @" 58c940c45833 007859d3ad71 000000000000 [EOF] "); // `-p` for default diff output, `-s` for summary let output = work_dir.run_jj(["log", "-T", "description", "-p", "-s"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ A file1 │ Added regular file file1: │ 1: foo ◆ [EOF] "); // `-s` for summary, `--git` for git diff (which implies `-p`) let output = work_dir.run_jj(["log", "-T", "description", "-s", "--git"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 │ diff --git a/file1 b/file1 │ index 257cc5642c..3bd1f0e297 100644 │ --- a/file1 │ +++ b/file1 │ @@ -1,1 +1,2 @@ │ foo │ +bar ○ add a file │ A file1 │ diff --git a/file1 b/file1 │ new file mode 100644 │ index 0000000000..257cc5642c │ --- /dev/null │ +++ b/file1 │ @@ -0,0 +1,1 @@ │ +foo ◆ [EOF] "); // `-p` for default diff output, `--stat` for diff-stat let output = work_dir.run_jj(["log", "-T", "description", "-p", "--stat"]); insta::assert_snapshot!(output, @" @ a new commit │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ Added regular file file1: │ 1: foo ◆ 0 files changed, 0 insertions(+), 0 deletions(-) [EOF] "); // `--stat` is short format, which should be printed first let output = work_dir.run_jj(["log", "-T", "description", "--git", "--stat"]); insta::assert_snapshot!(output, @" @ a new commit │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ diff --git a/file1 b/file1 │ index 257cc5642c..3bd1f0e297 100644 │ --- a/file1 │ +++ b/file1 │ @@ -1,1 +1,2 @@ │ foo │ +bar ○ add a file │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ diff --git a/file1 b/file1 │ new file mode 100644 │ index 0000000000..257cc5642c │ --- /dev/null │ +++ b/file1 │ @@ -0,0 +1,1 @@ │ +foo ◆ 0 files changed, 0 insertions(+), 0 deletions(-) [EOF] "); // `-p` enables default "summary" output, so `-s` is noop let output = work_dir.run_jj([ "log", "-T", "description", "-p", "-s", "--config=ui.diff-formatter=:summary", ]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 ○ add a file │ A file1 ◆ [EOF] "); // `-p` enables default "color-words" diff output, so `--color-words` is noop let output = work_dir.run_jj(["log", "-T", "description", "-p", "--color-words"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ Added regular file file1: │ 1: foo ◆ [EOF] "); // `--git` enables git diff, so `-p` is noop let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-p", "--git"]); insta::assert_snapshot!(output, @" a new commit diff --git a/file1 b/file1 index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar add a file diff --git a/file1 b/file1 new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/file1 @@ -0,0 +1,1 @@ +foo [EOF] "); // Cannot use both `--git` and `--color-words` let output = work_dir.run_jj([ "log", "-T", "description", "--no-graph", "-p", "--git", "--color-words", ]); insta::assert_snapshot!(output, @" ------- stderr ------- error: the argument '--git' cannot be used with '--color-words' Usage: jj log --template <TEMPLATE> --no-graph --patch --git [FILESETS]... For more information, try '--help'. [EOF] [exit status: 2] "); // `-s` with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-s"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 ○ add a file │ A file1 ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-s"]); insta::assert_snapshot!(output, @" a new commit M file1 add a file A file1 [EOF] "); // `--git` implies `-p`, with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--git"]); insta::assert_snapshot!(output, @" @ a new commit │ diff --git a/file1 b/file1 ~ index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--no-graph", "--git"]); insta::assert_snapshot!(output, @" a new commit diff --git a/file1 b/file1 index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar [EOF] "); // `--color-words` implies `-p`, with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--color-words"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: ~ 1 1: foo 2: bar [EOF] "); let output = work_dir.run_jj([ "log", "-T", "description", "-r", "@", "--no-graph", "--color-words", ]); insta::assert_snapshot!(output, @" a new commit Modified regular file file1: 1 1: foo 2: bar [EOF] ");} #[test]fn test_log_null_terminate_multiline_descriptions() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir .run_jj(["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"]) .success(); work_dir .run_jj(["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"]) .success(); work_dir .run_jj(["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"]) .success(); let output = work_dir .run_jj([ "log", "-r", "~root()", "-T", r#"description ++ "\0""#, "--no-graph", ]) .success(); insta::assert_debug_snapshot!( output.stdout.normalized(), @r#""commit 3 line 1\n\ncommit 3 line 2\n\0commit 2 line 1\n\ncommit 2 line 2\n\0commit 1 line 1\n\ncommit 1 line 2\n\0""# );} #[test]fn test_log_shortest_accessors() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let render = |rev, template| work_dir.run_jj(["log", "--no-graph", "-r", rev, "-T", template]); test_env.add_config( r#" [template-aliases] 'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"' "#, ); work_dir.write_file("file", "original file\n"); work_dir.run_jj(["describe", "-m", "initial"]).success(); work_dir .run_jj(["bookmark", "c", "-r@", "original"]) .success(); insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"q[pvuntsmwlqt] 8[216f646c36d][EOF]"); // Create a chain of 10 commits for i in 1..10 { work_dir .run_jj(["new", "-m", &format!("commit{i}")]) .success(); work_dir.write_file("file", format!("file {i}\n")); } // Create 2^3 duplicates of the chain for _ in 0..3 { work_dir.run_jj(["duplicate", "subject(commit*)"]).success(); } insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"qpv[untsmwlqt] 82[16f646c36d][EOF]"); insta::assert_snapshot!( render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#), @" wq c2 km 74 kp 97 zn 78 yo 40 vr bc9 yq 28 ro af mz 04Lines 1–500 of 1933. Load more
// Copyright 2022 The Jujutsu Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. use crate::common::TestEnvironment; use crate::common::to_toml_value; #[test] fn test_log_with_empty_revision() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["log", "-r="]); insta::assert_snapshot!(output, @" ------- stderr ------- error: a value is required for '--revision <REVSETS>' but none was supplied For more information, try '--help'. [EOF] [exit status: 2] "); } #[test] fn test_log_with_no_template() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["log", "-T"]); insta::assert_snapshot!(output, @" ------- stderr ------- error: a value is required for '--template <TEMPLATE>' but none was supplied For more information, try '--help'. Hint: The following template aliases are defined: - builtin_config_list - builtin_config_list_detailed - builtin_draft_commit_description - builtin_draft_commit_description_with_diff - builtin_evolog_compact - builtin_log_comfortable - builtin_log_compact - builtin_log_compact_full_description - builtin_log_detailed - builtin_log_node - builtin_log_node_ascii - builtin_log_oneline - builtin_log_redacted - builtin_op_log_comfortable - builtin_op_log_compact - builtin_op_log_node - builtin_op_log_node_ascii - builtin_op_log_oneline - builtin_op_log_redacted - builtin_workspace_list - commit_summary_separator - default_commit_description - description_placeholder - email_placeholder - empty_commit_marker - git_format_patch_email_headers - name_placeholder [EOF] [exit status: 2] "); } #[test] fn test_log_with_diff_stats() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\nfoo\n"); work_dir.write_file("file3", "foo\n"); work_dir.write_file("file4", "foo\n"); work_dir.write_file("file5", "foobar\nbaz\n"); work_dir .run_jj(["describe", "-m", "initial commit"]) .success(); work_dir.run_jj(["new", "-m", "multiple changes"]).success(); work_dir.write_file("file1", "foo\nbar\n"); work_dir.write_file("file2", "bar\n"); work_dir.write_file("file3", "baz\n"); work_dir.remove_file("file4"); work_dir.remove_file("file5"); work_dir.write_file("file6", "foobar\nbaz\n"); let template = r#" self.diff().files().map( |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.source().path() ++ " " ++ f.target().path() ).join("\n") ++ "\n" ++ self.diff().stat().files().map( |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.lines_added() ++ " " ++ f.lines_removed() ++ " " ++ f.path() ).join("\n") "#; let output = work_dir.run_jj(["log", "-T", template]); insta::assert_snapshot!(output, @" @ M modified file1 file1 │ M modified file2 file2 │ M modified file3 file3 │ D removed file4 file4 │ R renamed file5 file6 │ M modified 1 0 file1 │ M modified 0 1 file2 │ M modified 1 1 file3 │ D removed 0 1 file4 │ R renamed 0 0 file6 ○ A added file1 file1 │ A added file2 file2 │ A added file3 file3 │ A added file4 file4 │ A added file5 file5 │ A added 1 0 file1 │ A added 2 0 file2 │ A added 1 0 file3 │ A added 1 0 file4 │ A added 2 0 file5 ◆ [EOF] "); } #[test] fn test_log_with_or_without_diff() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.run_jj(["describe", "-m", "add a file"]).success(); work_dir.run_jj(["new", "-m", "a new commit"]).success(); work_dir.write_file("file1", "foo\nbar\n"); let output = work_dir.run_jj(["log", "-T", "description"]); insta::assert_snapshot!(output, @" @ a new commit ○ add a file ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "-p"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ Added regular file file1: │ 1: foo ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "--no-graph"]); insta::assert_snapshot!(output, @" a new commit add a file [EOF] "); // `-G` is the short name of --no-graph let output = work_dir.run_jj(["log", "-T", r#"commit_id.short() ++ "\n""#, "-G"]); insta::assert_snapshot!(output, @" 58c940c45833 007859d3ad71 000000000000 [EOF] "); // `-p` for default diff output, `-s` for summary let output = work_dir.run_jj(["log", "-T", "description", "-p", "-s"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ A file1 │ Added regular file file1: │ 1: foo ◆ [EOF] "); // `-s` for summary, `--git` for git diff (which implies `-p`) let output = work_dir.run_jj(["log", "-T", "description", "-s", "--git"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 │ diff --git a/file1 b/file1 │ index 257cc5642c..3bd1f0e297 100644 │ --- a/file1 │ +++ b/file1 │ @@ -1,1 +1,2 @@ │ foo │ +bar ○ add a file │ A file1 │ diff --git a/file1 b/file1 │ new file mode 100644 │ index 0000000000..257cc5642c │ --- /dev/null │ +++ b/file1 │ @@ -0,0 +1,1 @@ │ +foo ◆ [EOF] "); // `-p` for default diff output, `--stat` for diff-stat let output = work_dir.run_jj(["log", "-T", "description", "-p", "--stat"]); insta::assert_snapshot!(output, @" @ a new commit │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ Added regular file file1: │ 1: foo ◆ 0 files changed, 0 insertions(+), 0 deletions(-) [EOF] "); // `--stat` is short format, which should be printed first let output = work_dir.run_jj(["log", "-T", "description", "--git", "--stat"]); insta::assert_snapshot!(output, @" @ a new commit │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ diff --git a/file1 b/file1 │ index 257cc5642c..3bd1f0e297 100644 │ --- a/file1 │ +++ b/file1 │ @@ -1,1 +1,2 @@ │ foo │ +bar ○ add a file │ file1 | 1 + │ 1 file changed, 1 insertion(+), 0 deletions(-) │ diff --git a/file1 b/file1 │ new file mode 100644 │ index 0000000000..257cc5642c │ --- /dev/null │ +++ b/file1 │ @@ -0,0 +1,1 @@ │ +foo ◆ 0 files changed, 0 insertions(+), 0 deletions(-) [EOF] "); // `-p` enables default "summary" output, so `-s` is noop let output = work_dir.run_jj([ "log", "-T", "description", "-p", "-s", "--config=ui.diff-formatter=:summary", ]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 ○ add a file │ A file1 ◆ [EOF] "); // `-p` enables default "color-words" diff output, so `--color-words` is noop let output = work_dir.run_jj(["log", "-T", "description", "-p", "--color-words"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ○ add a file │ Added regular file file1: │ 1: foo ◆ [EOF] "); // `--git` enables git diff, so `-p` is noop let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-p", "--git"]); insta::assert_snapshot!(output, @" a new commit diff --git a/file1 b/file1 index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar add a file diff --git a/file1 b/file1 new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/file1 @@ -0,0 +1,1 @@ +foo [EOF] "); // Cannot use both `--git` and `--color-words` let output = work_dir.run_jj([ "log", "-T", "description", "--no-graph", "-p", "--git", "--color-words", ]); insta::assert_snapshot!(output, @" ------- stderr ------- error: the argument '--git' cannot be used with '--color-words' Usage: jj log --template <TEMPLATE> --no-graph --patch --git [FILESETS]... For more information, try '--help'. [EOF] [exit status: 2] "); // `-s` with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-s"]); insta::assert_snapshot!(output, @" @ a new commit │ M file1 ○ add a file │ A file1 ◆ [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-s"]); insta::assert_snapshot!(output, @" a new commit M file1 add a file A file1 [EOF] "); // `--git` implies `-p`, with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--git"]); insta::assert_snapshot!(output, @" @ a new commit │ diff --git a/file1 b/file1 ~ index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar [EOF] "); let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--no-graph", "--git"]); insta::assert_snapshot!(output, @" a new commit diff --git a/file1 b/file1 index 257cc5642c..3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar [EOF] "); // `--color-words` implies `-p`, with or without graph let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--color-words"]); insta::assert_snapshot!(output, @" @ a new commit │ Modified regular file file1: ~ 1 1: foo 2: bar [EOF] "); let output = work_dir.run_jj([ "log", "-T", "description", "-r", "@", "--no-graph", "--color-words", ]); insta::assert_snapshot!(output, @" a new commit Modified regular file file1: 1 1: foo 2: bar [EOF] "); } #[test] fn test_log_null_terminate_multiline_descriptions() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); work_dir .run_jj(["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"]) .success(); work_dir .run_jj(["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"]) .success(); work_dir .run_jj(["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"]) .success(); let output = work_dir .run_jj([ "log", "-r", "~root()", "-T", r#"description ++ "\0""#, "--no-graph", ]) .success(); insta::assert_debug_snapshot!( output.stdout.normalized(), @r#""commit 3 line 1\n\ncommit 3 line 2\n\0commit 2 line 1\n\ncommit 2 line 2\n\0commit 1 line 1\n\ncommit 1 line 2\n\0""# ); } #[test] fn test_log_shortest_accessors() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); let render = |rev, template| work_dir.run_jj(["log", "--no-graph", "-r", rev, "-T", template]); test_env.add_config( r#" [template-aliases] 'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"' "#, ); work_dir.write_file("file", "original file\n"); work_dir.run_jj(["describe", "-m", "initial"]).success(); work_dir .run_jj(["bookmark", "c", "-r@", "original"]) .success(); insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"q[pvuntsmwlqt] 8[216f646c36d][EOF]"); // Create a chain of 10 commits for i in 1..10 { work_dir .run_jj(["new", "-m", &format!("commit{i}")]) .success(); work_dir.write_file("file", format!("file {i}\n")); } // Create 2^3 duplicates of the chain for _ in 0..3 { work_dir.run_jj(["duplicate", "subject(commit*)"]).success(); } insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"qpv[untsmwlqt] 82[16f646c36d][EOF]"); insta::assert_snapshot!( render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#), @" wq c2 km 74 kp 97 zn 78 yo 40 vr bc9 yq 28 ro af mz 04