mirror of
https://github.com/jj-vcs/jj.git
synced 2025-12-23 06:01:01 +00:00
Now that we can put the "from" and "to" sides on separate lines, we can use the normal "(no terminating newline)" comment on each side separately. This should also be more clear, since previously the "(no terminating newline)" comment could possibly be confused for "(removes terminating newline)". Before: ``` <<<<<<< conflict 1 of 1 +++++++ rtsqusxu 2768b0b9 "commit A" (no terminating newline) grapefruit %%%%%%% diff from: vpxusssl 38d49363 "merge base" \\\\\\\ to: ysrnknol 7a20f389 "commit B" (adds terminating newline) -grape +grape >>>>>>> conflict 1 of 1 ends ``` After: ``` <<<<<<< conflict 1 of 1 +++++++ rtsqusxu 2768b0b9 "commit A" (no terminating newline) grapefruit %%%%%%% diff from: vpxusssl 38d49363 "merge base" (no terminating newline) \\\\\\\ to: ysrnknol 7a20f389 "commit B" -grape +grape >>>>>>> conflict 1 of 1 ends ```
110 lines
3.8 KiB
Rust
110 lines
3.8 KiB
Rust
// Copyright 2025 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;
|
|
|
|
#[test]
|
|
fn test_file_search() {
|
|
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-");
|
|
work_dir.write_file("file2", "-bar-");
|
|
work_dir.run_jj(["new"]).success();
|
|
work_dir.create_dir("dir");
|
|
work_dir.write_file("dir/file3", "-foobar-");
|
|
|
|
// Searches all files in the current revision by default
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*foo*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
dir/file3
|
|
file1
|
|
[EOF]
|
|
");
|
|
|
|
// Matches only the whole line
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=foo"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @"");
|
|
|
|
// Can search files in another revision
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*foo*", "-r=@-"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
file1
|
|
[EOF]
|
|
");
|
|
|
|
// Can filter by path
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*foo*", "dir"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
dir/file3
|
|
[EOF]
|
|
");
|
|
|
|
// Warning if path doesn't exist
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*foo*", "file9"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
------- stderr -------
|
|
Warning: No matching entries for paths: file9
|
|
[EOF]
|
|
");
|
|
}
|
|
|
|
#[test]
|
|
fn test_file_search_conflicts() {
|
|
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-");
|
|
work_dir.run_jj(["new"]).success();
|
|
work_dir.write_file("file1", "-bar-");
|
|
work_dir.run_jj(["new"]).success();
|
|
work_dir.write_file("file1", "-baz-");
|
|
work_dir.run_jj(["rebase", "-r=@", "-B=@-"]).success();
|
|
|
|
// Test the setup
|
|
insta::assert_snapshot!(work_dir.read_file("file1"), @r"
|
|
<<<<<<< conflict 1 of 1
|
|
%%%%%%% diff from: rlvkpnrz 958d516d (parents of rebased commit) (no terminating newline)
|
|
\\\\\\\ to: qpvuntsm 6da222ee (rebase destination) (no terminating newline)
|
|
--bar-
|
|
+-foo-
|
|
+++++++ kkmpptxz 95e61837 (rebased commit) (no terminating newline)
|
|
-baz-
|
|
>>>>>>> conflict 1 of 1 ends
|
|
");
|
|
|
|
// Matches positive terms
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*foo*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
file1
|
|
[EOF]
|
|
");
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*bar*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @"");
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*baz*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @r"
|
|
file1
|
|
[EOF]
|
|
");
|
|
|
|
// Doesn't match the conflict markers
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*%%%*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @"");
|
|
|
|
// Doesn't list file if the pattern doesn't match
|
|
let output = work_dir.run_jj(["file", "search", "--pattern=*qux*"]);
|
|
insta::assert_snapshot!(output.normalize_backslash(), @"");
|
|
}
|