Debian Codegraph @

cli/tests/test_file_list_command.rs

raw
1 // Copyright 2025 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use indoc::indoc;
16
17 use crate::common::TestEnvironment;
18
19 #[test]
20 fn test_file_list() {
21 let test_env = TestEnvironment::default();
22 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
23 let work_dir = test_env.work_dir("repo");
24
25 work_dir.create_dir("dir");
26 work_dir.write_file("dir/file", "content1");
27 work_dir.write_file("exec-file", "content1");
28 work_dir.write_file("conflict-exec-file", "content1");
29 work_dir.write_file("conflict-file", "content1");
30 work_dir
31 .run_jj(["file", "chmod", "x", "exec-file", "conflict-exec-file"])
32 .success();
33
34 work_dir.run_jj(["new", "root()"]).success();
35 work_dir.write_file("conflict-exec-file", "content2");
36 work_dir.write_file("conflict-file", "content2");
37 work_dir
38 .run_jj(["file", "chmod", "x", "conflict-exec-file"])
39 .success();
40
41 work_dir.run_jj(["new", "visible_heads()"]).success();
42
43 // Lists all files in the current revision by default
44 let output = work_dir.run_jj(["file", "list"]);
45 insta::assert_snapshot!(output.normalize_backslash(), @"
46 conflict-exec-file
47 conflict-file
48 dir/file
49 exec-file
50 [EOF]
51 ");
52
53 // Can list with templates
54 let template = indoc! {r#"
55 separate(" ",
56 path,
57 "[" ++ file_type ++ "]",
58 "conflict=" ++ conflict,
59 "executable=" ++ executable,
60 ) ++ "\n"
61 "#};
62 let output = work_dir.run_jj(["file", "list", "-T", template]);
63 insta::assert_snapshot!(output.normalize_backslash(), @"
64 conflict-exec-file [conflict] conflict=true executable=true
65 conflict-file [conflict] conflict=true executable=false
66 dir/file [file] conflict=false executable=false
67 exec-file [file] conflict=false executable=true
68 [EOF]
69 ");
70
71 // Can list files in another revision
72 let output = work_dir.run_jj(["file", "list", "-r=first_parent(@)"]);
73 insta::assert_snapshot!(output.normalize_backslash(), @"
74 conflict-exec-file
75 conflict-file
76 [EOF]
77 ");
78
79 // Can filter by path
80 let output = work_dir.run_jj(["file", "list", "dir"]);
81 insta::assert_snapshot!(output.normalize_backslash(), @"
82 dir/file
83 [EOF]
84 ");
85
86 // Warning if path doesn't exist
87 let output = work_dir.run_jj(["file", "list", "dir", "file3"]);
88 insta::assert_snapshot!(output.normalize_backslash(), @"
89 dir/file
90 [EOF]
91 ------- stderr -------
92 Warning: No matching entries for paths: file3
93 [EOF]
94 ");
95 }