// 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_stderr_string, get_stdout_string, TestEnvironment}; pub mod common; #[test] fn test_log_with_empty_revision() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(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 ' but none was supplied For more information, try '--help'. "###); } #[test] fn test_log_with_or_without_diff() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(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_success(&repo_path, &["describe", "-m", "add a file"]); test_env.jj_cmd_success(&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