Debian Codegraph @

cli/tests/test_acls.rs

raw
1 // Copyright 2024 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 jj_lib::secret_backend::SecretBackend;
16
17 use crate::common::TestEnvironment;
18
19 #[test]
20 fn test_diff() {
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("a-first", "foo\n");
27 work_dir.write_file("deleted-secret", "foo\n");
28 work_dir.write_file("dir/secret", "foo\n");
29 work_dir.write_file("modified-secret", "foo\n");
30 work_dir.write_file("z-last", "foo\n");
31 work_dir.run_jj(["new"]).success();
32 work_dir.write_file("a-first", "bar\n");
33 work_dir.remove_file("deleted-secret");
34 work_dir.write_file("added-secret", "bar\n");
35 work_dir.write_file("dir/secret", "bar\n");
36 work_dir.write_file("modified-secret", "bar\n");
37 work_dir.write_file("z-last", "bar\n");
38
39 SecretBackend::adopt_git_repo(work_dir.root());
40
41 let output = work_dir.run_jj(["diff", "--color-words"]);
42 insta::assert_snapshot!(output.normalize_backslash(), @"
43 Modified regular file a-first:
44 1 : foo
45 1: bar
46 Access denied to added-secret: No access
47 Access denied to deleted-secret: No access
48 Access denied to dir/secret: No access
49 Access denied to modified-secret: No access
50 Modified regular file z-last:
51 1 : foo
52 1: bar
53 [EOF]
54 ");
55 let output = work_dir.run_jj(["diff", "--summary"]);
56 insta::assert_snapshot!(output.normalize_backslash(), @"
57 M a-first
58 C {a-first => added-secret}
59 D deleted-secret
60 M dir/secret
61 M modified-secret
62 M z-last
63 [EOF]
64 ");
65 let output = work_dir.run_jj(["diff", "--types"]);
66 insta::assert_snapshot!(output.normalize_backslash(), @"
67 FF a-first
68 FF {a-first => added-secret}
69 F- deleted-secret
70 FF dir/secret
71 FF modified-secret
72 FF z-last
73 [EOF]
74 ");
75 let output = work_dir.run_jj(["diff", "--stat"]);
76 insta::assert_snapshot!(output.normalize_backslash(), @"
77 a-first | 2 +-
78 {a-first => added-secret} | 2 +-
79 deleted-secret | 1 -
80 dir/secret | 0
81 modified-secret | 0
82 z-last | 2 +-
83 6 files changed, 3 insertions(+), 4 deletions(-)
84 [EOF]
85 ");
86 let output = work_dir.run_jj(["diff", "--git"]);
87 insta::assert_snapshot!(output.normalize_backslash(), @"
88 diff --git a/a-first b/a-first
89 index 257cc5642c..5716ca5987 100644
90 --- a/a-first
91 +++ b/a-first
92 @@ -1,1 +1,1 @@
93 -foo
94 +bar
95 [EOF]
96 ------- stderr -------
97 Error: Access denied to added-secret
98 Caused by: No access
99 [EOF]
100 [exit status: 1]
101 ");
102
103 // TODO: Test external tool
104 }
105
106 #[test]
107 fn test_file_list_show() {
108 let test_env = TestEnvironment::default();
109 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
110 let work_dir = test_env.work_dir("repo");
111
112 work_dir.write_file("a-first", "foo\n");
113 work_dir.write_file("secret", "bar\n");
114 work_dir.write_file("z-last", "baz\n");
115
116 SecretBackend::adopt_git_repo(work_dir.root());
117
118 // "file list" should just work since it doesn't access file content
119 let output = work_dir.run_jj(["file", "list"]);
120 insta::assert_snapshot!(output, @"
121 a-first
122 secret
123 z-last
124 [EOF]
125 ");
126
127 let output = work_dir.run_jj(["file", "show", "."]);
128 insta::assert_snapshot!(output.normalize_backslash(), @"
129 foo
130 baz
131 [EOF]
132 ------- stderr -------
133 Warning: Path 'secret' exists but access is denied: No access
134 [EOF]
135 ");
136 }