// 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 common::{get_stdout_string, TestEnvironment}; pub mod common; #[test]fn test_log_with_empty_revision() { 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"); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-r="]); insta::assert_snapshot!(stderr, @r###" error: a value is required for '--revisions <REVISIONS>' but none was supplied For more information, try '--help'. "###);} #[test]fn test_log_legacy_range_operator() { 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"); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=@:"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ~ "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=:@"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ◉ zzzzzzzz root() 00000000 "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=root():@"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ◉ zzzzzzzz root() 00000000 "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok( &repo_path, &["log", "-r=x", "--config-toml", "revset-aliases.x = '@:'"], ); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ~ "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###);} #[test]fn test_log_with_or_without_diff() { 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"); std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]); test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]); std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap(); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]); insta::assert_snapshot!(stdout, @r###" @ a new commit ◉ add a file ◉ "###); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p"]); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ◉ add a file │ Added regular file file1: │ 1: foo ◉ "###); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--no-graph"]); insta::assert_snapshot!(stdout, @r###" a new commit add a file "###); // `-p` for default diff output, `-s` for summary let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p", "-s"]); insta::assert_snapshot!(stdout, @r###" @ 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 ◉ "###); // `-s` for summary, `--git` for git diff (which implies `-p`) let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s", "--git"]); insta::assert_snapshot!(stdout, @r###" @ 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 │ @@ -1,0 +1,1 @@ │ +foo ◉ "###); // `-p` enables default "summary" output, so `-s` is noop let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-T", "description", "-p", "-s", "--config-toml=ui.diff.format='summary'", ], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ M file1 ◉ add a file │ A file1 ◉ "###); // `-p` enables default "color-words" diff output, so `--color-words` is noop let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-p", "--color-words"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ◉ add a file │ Added regular file file1: │ 1: foo ◉ "###); // `--git` enables git diff, so `-p` is noop let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "--no-graph", "-p", "--git"], ); insta::assert_snapshot!(stdout, @r###" 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 @@ -1,0 +1,1 @@ +foo "###); // Cannot use both `--git` and `--color-words` let stderr = test_env.jj_cmd_cli_error( &repo_path, &[ "log", "-T", "description", "--no-graph", "-p", "--git", "--color-words", ], ); insta::assert_snapshot!(stderr, @r###" error: the argument '--git' cannot be used with '--color-words' Usage: jj log --template <TEMPLATE> --no-graph --patch --git [PATHS]... For more information, try '--help'. "###); // `-s` with or without graph let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s"]); insta::assert_snapshot!(stdout, @r###" @ a new commit │ M file1 ◉ add a file │ A file1 ◉ "###); let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "--no-graph", "-s"], ); insta::assert_snapshot!(stdout, @r###" a new commit M file1 add a file A file1 "###); // `--git` implies `-p`, with or without graph let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--git"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ diff --git a/file1 b/file1 ~ index 257cc5642c...3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar "###); let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--no-graph", "--git"], ); insta::assert_snapshot!(stdout, @r###" a new commit diff --git a/file1 b/file1 index 257cc5642c...3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar "###); // `--color-words` implies `-p`, with or without graph let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--color-words"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: ~ 1 1: foo 2: bar "###); let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-T", "description", "-r", "@", "--no-graph", "--color-words", ], ); insta::assert_snapshot!(stdout, @r###" a new commit Modified regular file file1: 1 1: foo 2: bar "###);} #[test]fn test_log_null_terminate_multiline_descriptions() { 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, &["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"], ); test_env.jj_cmd_ok( &repo_path, &["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"], ); test_env.jj_cmd_ok( &repo_path, &["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"], ); let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-r", "~root()", "-T", r#"description ++ "\0""#, "--no-graph", ], ); insta::assert_debug_snapshot!( stdout, @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.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); let render = |rev, template| { test_env.jj_cmd_success( &repo_path, &["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() ++ "]"' "#, ); std::fs::write(repo_path.join("file"), "original file\n").unwrap(); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]); test_env.jj_cmd_ok(&repo_path, &["branch", "c", "original"]); insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"q[pvuntsmwlqt] b[a1a30916d29]"); // Create a chain of 10 commits for i in 1..10 { test_env.jj_cmd_ok(&repo_path, &["new", "-m", &format!("commit{i}")]); std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap(); } // Create 2^3 duplicates of the chain for _ in 0..3 { test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]); } insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"qpv[untsmwlqt] ba1[a30916d29]"); insta::assert_snapshot!( render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#), @r###" wq 03 km f7 kp e7 zn 38 yo 0cf vr 9e yq 06 ro 1f mz 7b qpv ba1 zzz 00 "###); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" wq[nwkozpkust] 03[f51310b83e] km[kuslswpqwq] f7[7fb1909080] kp[qxywonksrl] e7[15ad5db646] zn[kkpsqqskkl] 38[622e54e2e5] yo[stqsxwqrlt] 0cf[42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06[f34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###); // Can get shorter prefixes in configured revset test_env.add_config(r#"revsets.short-prefixes = "(@----):""#); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" w[qnwkozpkust] 03[f51310b83e] km[kuslswpqwq] f[77fb1909080] kp[qxywonksrl] e[715ad5db646] z[nkkpsqqskkl] 3[8622e54e2e5] y[ostqsxwqrlt] 0c[f42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06f[34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###); // Can disable short prefixes by setting to empty string test_env.add_config(r#"revsets.short-prefixes = """#); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" wq[nwkozpkust] 03[f51310b83e] km[kuslswpqwq] f7[7fb1909080] kp[qxywonksrl] e7[15ad5db646] zn[kkpsqqskkl] 38[622e54e2e5] yo[stqsxwqrlt] 0cf[42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06f[34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###);} #[test]fn test_log_bad_short_prefixes() { 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"); // Error on bad config of short prefixes test_env.add_config(r#"revsets.short-prefixes = "!nval!d""#); let stderr = test_env.jj_cmd_failure(&repo_path, &["status"]); insta::assert_snapshot!(stderr, @r###" Config error: Invalid `revsets.short-prefixes`: --> 1:1 | 1 | !nval!d | ^--- | = expected <expression> For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md. "###);} #[test]fn test_log_prefix_highlight_styled() { 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"); fn prefix_format(len: Option<usize>) -> String { format!( r###" separate(" ", "Change", change_id.shortest({0}), description.first_line(), commit_id.shortest({0}), branches, ) "###, len.map(|l| l.to_string()).unwrap_or_default() ) }Lines 1–500 of 1359. 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 common::{get_stdout_string, TestEnvironment}; pub mod common; #[test] fn test_log_with_empty_revision() { 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"); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-r="]); insta::assert_snapshot!(stderr, @r###" error: a value is required for '--revisions <REVISIONS>' but none was supplied For more information, try '--help'. "###); } #[test] fn test_log_legacy_range_operator() { 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"); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=@:"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ~ "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=:@"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ◉ zzzzzzzz root() 00000000 "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=root():@"]); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ◉ zzzzzzzz root() 00000000 "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); let (stdout, stderr) = test_env.jj_cmd_ok( &repo_path, &["log", "-r=x", "--config-toml", "revset-aliases.x = '@:'"], ); insta::assert_snapshot!(stdout, @r###" @ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059 │ (empty) (no description set) ~ "###); insta::assert_snapshot!(stderr, @r###" The `:` revset operator is deprecated. Please switch to `::`. "###); } #[test] fn test_log_with_or_without_diff() { 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"); std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]); test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]); std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap(); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]); insta::assert_snapshot!(stdout, @r###" @ a new commit ◉ add a file ◉ "###); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p"]); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ◉ add a file │ Added regular file file1: │ 1: foo ◉ "###); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--no-graph"]); insta::assert_snapshot!(stdout, @r###" a new commit add a file "###); // `-p` for default diff output, `-s` for summary let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p", "-s"]); insta::assert_snapshot!(stdout, @r###" @ 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 ◉ "###); // `-s` for summary, `--git` for git diff (which implies `-p`) let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s", "--git"]); insta::assert_snapshot!(stdout, @r###" @ 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 │ @@ -1,0 +1,1 @@ │ +foo ◉ "###); // `-p` enables default "summary" output, so `-s` is noop let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-T", "description", "-p", "-s", "--config-toml=ui.diff.format='summary'", ], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ M file1 ◉ add a file │ A file1 ◉ "###); // `-p` enables default "color-words" diff output, so `--color-words` is noop let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-p", "--color-words"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: │ 1 1: foo │ 2: bar ◉ add a file │ Added regular file file1: │ 1: foo ◉ "###); // `--git` enables git diff, so `-p` is noop let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "--no-graph", "-p", "--git"], ); insta::assert_snapshot!(stdout, @r###" 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 @@ -1,0 +1,1 @@ +foo "###); // Cannot use both `--git` and `--color-words` let stderr = test_env.jj_cmd_cli_error( &repo_path, &[ "log", "-T", "description", "--no-graph", "-p", "--git", "--color-words", ], ); insta::assert_snapshot!(stderr, @r###" error: the argument '--git' cannot be used with '--color-words' Usage: jj log --template <TEMPLATE> --no-graph --patch --git [PATHS]... For more information, try '--help'. "###); // `-s` with or without graph let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s"]); insta::assert_snapshot!(stdout, @r###" @ a new commit │ M file1 ◉ add a file │ A file1 ◉ "###); let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "--no-graph", "-s"], ); insta::assert_snapshot!(stdout, @r###" a new commit M file1 add a file A file1 "###); // `--git` implies `-p`, with or without graph let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--git"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ diff --git a/file1 b/file1 ~ index 257cc5642c...3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar "###); let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--no-graph", "--git"], ); insta::assert_snapshot!(stdout, @r###" a new commit diff --git a/file1 b/file1 index 257cc5642c...3bd1f0e297 100644 --- a/file1 +++ b/file1 @@ -1,1 +1,2 @@ foo +bar "###); // `--color-words` implies `-p`, with or without graph let stdout = test_env.jj_cmd_success( &repo_path, &["log", "-T", "description", "-r", "@", "--color-words"], ); insta::assert_snapshot!(stdout, @r###" @ a new commit │ Modified regular file file1: ~ 1 1: foo 2: bar "###); let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-T", "description", "-r", "@", "--no-graph", "--color-words", ], ); insta::assert_snapshot!(stdout, @r###" a new commit Modified regular file file1: 1 1: foo 2: bar "###); } #[test] fn test_log_null_terminate_multiline_descriptions() { 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, &["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"], ); test_env.jj_cmd_ok( &repo_path, &["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"], ); test_env.jj_cmd_ok( &repo_path, &["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"], ); let stdout = test_env.jj_cmd_success( &repo_path, &[ "log", "-r", "~root()", "-T", r#"description ++ "\0""#, "--no-graph", ], ); insta::assert_debug_snapshot!( stdout, @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.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); let render = |rev, template| { test_env.jj_cmd_success( &repo_path, &["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() ++ "]"' "#, ); std::fs::write(repo_path.join("file"), "original file\n").unwrap(); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]); test_env.jj_cmd_ok(&repo_path, &["branch", "c", "original"]); insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"q[pvuntsmwlqt] b[a1a30916d29]"); // Create a chain of 10 commits for i in 1..10 { test_env.jj_cmd_ok(&repo_path, &["new", "-m", &format!("commit{i}")]); std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap(); } // Create 2^3 duplicates of the chain for _ in 0..3 { test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]); } insta::assert_snapshot!( render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#), @"qpv[untsmwlqt] ba1[a30916d29]"); insta::assert_snapshot!( render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#), @r###" wq 03 km f7 kp e7 zn 38 yo 0cf vr 9e yq 06 ro 1f mz 7b qpv ba1 zzz 00 "###); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" wq[nwkozpkust] 03[f51310b83e] km[kuslswpqwq] f7[7fb1909080] kp[qxywonksrl] e7[15ad5db646] zn[kkpsqqskkl] 38[622e54e2e5] yo[stqsxwqrlt] 0cf[42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06[f34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###); // Can get shorter prefixes in configured revset test_env.add_config(r#"revsets.short-prefixes = "(@----):""#); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" w[qnwkozpkust] 03[f51310b83e] km[kuslswpqwq] f[77fb1909080] kp[qxywonksrl] e[715ad5db646] z[nkkpsqqskkl] 3[8622e54e2e5] y[ostqsxwqrlt] 0c[f42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06f[34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###); // Can disable short prefixes by setting to empty string test_env.add_config(r#"revsets.short-prefixes = """#); insta::assert_snapshot!( render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" wq[nwkozpkust] 03[f51310b83e] km[kuslswpqwq] f7[7fb1909080] kp[qxywonksrl] e7[15ad5db646] zn[kkpsqqskkl] 38[622e54e2e5] yo[stqsxwqrlt] 0cf[42f60199c] vr[uxwmqvtpmx] 9e[6015e4e622] yq[osqzytrlsw] 06f[34d9b1475] ro[yxmykxtrkr] 1f[99a5e19891] mz[vwutvlkqwt] 7b[1f7dee65b4] qpv[untsmwlqt] ba1[a30916d29] zzz[zzzzzzzzz] 00[0000000000] "###); } #[test] fn test_log_bad_short_prefixes() { 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"); // Error on bad config of short prefixes test_env.add_config(r#"revsets.short-prefixes = "!nval!d""#); let stderr = test_env.jj_cmd_failure(&repo_path, &["status"]); insta::assert_snapshot!(stderr, @r###" Config error: Invalid `revsets.short-prefixes`: --> 1:1 | 1 | !nval!d | ^--- | = expected <expression> For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md. "###); } #[test] fn test_log_prefix_highlight_styled() { 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"); fn prefix_format(len: Option<usize>) -> String { format!( r###" separate(" ", "Change", change_id.shortest({0}), description.first_line(), commit_id.shortest({0}), branches, ) "###, len.map(|l| l.to_string()).unwrap_or_default() ) }