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