forked from mirrors/jj
0865b1ccff
It can be confusing that some commits (typically the working copy) don't have a description. Let's show a placeholder text in such cases. I chose the format to match the "(no email configured)" message we already have.
157 lines
4.4 KiB
Rust
157 lines
4.4 KiB
Rust
// Copyright 2022 Google LLC
|
|
//
|
|
// 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::TestEnvironment;
|
|
|
|
pub mod common;
|
|
|
|
#[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
|
|
o add a file
|
|
o (no description set)
|
|
"###);
|
|
|
|
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
|
|
o add a file
|
|
| Added regular file file1:
|
|
| 1: foo
|
|
o (no description set)
|
|
"###);
|
|
|
|
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
|
|
(no description set)
|
|
"###);
|
|
|
|
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
|
|
(no description set)
|
|
"###);
|
|
|
|
// `-s` implies `-p`, 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
|
|
o add a file
|
|
| A file1
|
|
o (no description set)
|
|
"###);
|
|
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
|
|
(no description set)
|
|
"###);
|
|
|
|
// `--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
|
|
"###);
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_reversed() {
|
|
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");
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
|
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--reversed"]);
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
o (no description set)
|
|
o first
|
|
@ second
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
&repo_path,
|
|
&["log", "-T", "description", "--reversed", "--no-graph"],
|
|
);
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
(no description set)
|
|
first
|
|
second
|
|
"###);
|
|
}
|