just playing with tangled
at ig/vimdiffwarn 239 lines 7.7 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 crate::common::create_commit_with_files; 16use crate::common::CommandOutput; 17use crate::common::TestEnvironment; 18use crate::common::TestWorkDir; 19 20#[test] 21fn test_backout() { 22 let test_env = TestEnvironment::default(); 23 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 24 let work_dir = test_env.work_dir("repo"); 25 26 create_commit_with_files(&work_dir, "a", &[], &[("a", "a\n")]); 27 // Test the setup 28 insta::assert_snapshot!(get_log_output(&work_dir), @r" 29 @ 2443ea76b0b1 a 30 ◆ 000000000000 31 [EOF] 32 "); 33 let output = work_dir.run_jj(["diff", "-s"]); 34 insta::assert_snapshot!(output, @r" 35 A a 36 [EOF] 37 "); 38 39 // Backout the commit 40 let output = work_dir.run_jj(["backout", "-r", "@"]); 41 insta::assert_snapshot!(output, @r" 42 ------- stderr ------- 43 Warning: `jj backout` is deprecated; use `jj revert` instead 44 Warning: `jj backout` will be removed in a future version, and this will be a hard error 45 [EOF] 46 "); 47 insta::assert_snapshot!(get_log_output(&work_dir), @r#" 48 ○ 6d845ed9fb6a Back out "a" 49 50 │ This backs out commit 2443ea76b0b1c531326908326aab7020abab8e6c. 51 @ 2443ea76b0b1 a 52 ◆ 000000000000 53 [EOF] 54 "#); 55 let output = work_dir.run_jj(["diff", "-s", "-r", "@+"]); 56 insta::assert_snapshot!(output, @r" 57 D a 58 [EOF] 59 "); 60 61 // Backout the new backed-out commit 62 work_dir.run_jj(["edit", "@+"]).success(); 63 let output = work_dir.run_jj(["backout", "-r", "@"]); 64 insta::assert_snapshot!(output, @r" 65 ------- stderr ------- 66 Warning: `jj backout` is deprecated; use `jj revert` instead 67 Warning: `jj backout` will be removed in a future version, and this will be a hard error 68 [EOF] 69 "); 70 insta::assert_snapshot!(get_log_output(&work_dir), @r#" 71 ○ 79555ea9040b Back out "Back out "a"" 72 73 │ This backs out commit 6d845ed9fb6a3d367e2d7068ef0256b1a10705a9. 74 @ 6d845ed9fb6a Back out "a" 75 76 │ This backs out commit 2443ea76b0b1c531326908326aab7020abab8e6c. 77 ○ 2443ea76b0b1 a 78 ◆ 000000000000 79 [EOF] 80 "#); 81 let output = work_dir.run_jj(["diff", "-s", "-r", "@+"]); 82 insta::assert_snapshot!(output, @r" 83 A a 84 [EOF] 85 "); 86} 87 88#[test] 89fn test_backout_multiple() { 90 let test_env = TestEnvironment::default(); 91 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 92 let work_dir = test_env.work_dir("repo"); 93 94 create_commit_with_files(&work_dir, "a", &[], &[("a", "a\n")]); 95 create_commit_with_files(&work_dir, "b", &["a"], &[("a", "a\nb\n")]); 96 create_commit_with_files(&work_dir, "c", &["b"], &[("a", "a\nb\n"), ("b", "b\n")]); 97 create_commit_with_files(&work_dir, "d", &["c"], &[]); 98 create_commit_with_files(&work_dir, "e", &["d"], &[("a", "a\nb\nc\n")]); 99 100 // Test the setup 101 insta::assert_snapshot!(get_log_output(&work_dir), @r" 102 @ 208f8612074a e 103 ○ ceeec03be46b d 104 ○ 413337bbd11f c 105 ○ 46cc97af6802 b 106 ○ 2443ea76b0b1 a 107 ◆ 000000000000 108 [EOF] 109 "); 110 111 // Backout multiple commits 112 let output = work_dir.run_jj(["backout", "-r", "b", "-r", "c", "-r", "e"]); 113 insta::assert_snapshot!(output, @r" 114 ------- stderr ------- 115 Warning: `jj backout` is deprecated; use `jj revert` instead 116 Warning: `jj backout` will be removed in a future version, and this will be a hard error 117 [EOF] 118 "); 119 insta::assert_snapshot!(get_log_output(&work_dir), @r#" 120 ○ 6504c4ded177 Back out "b" 121122 │ This backs out commit 46cc97af6802301d8db381386e8485ff3ff24ae6. 123 ○ d31d42e0267f Back out "c" 124125 │ This backs out commit 413337bbd11f7a6636c010d9e196acf801d8df2f. 126 ○ 8ff3fbc2ccb0 Back out "e" 127128 │ This backs out commit 208f8612074af4c219d06568a8e1f04f2e80dc25. 129 @ 208f8612074a e 130 ○ ceeec03be46b d 131 ○ 413337bbd11f c 132 ○ 46cc97af6802 b 133 ○ 2443ea76b0b1 a 134 ◆ 000000000000 135 [EOF] 136 "#); 137 // View the output of each backed out commit 138 let output = work_dir.run_jj(["show", "@+"]); 139 insta::assert_snapshot!(output, @r#" 140 Commit ID: 8ff3fbc2ccb0d66985f558c461d1643cebb4c7d6 141 Change ID: wqnwkozpkustnxypnnntnykwrqrkrpvv 142 Author : Test User <test.user@example.com> (2001-02-03 08:05:19) 143 Committer: Test User <test.user@example.com> (2001-02-03 08:05:19) 144 145 Back out "e" 146 147 This backs out commit 208f8612074af4c219d06568a8e1f04f2e80dc25. 148 149 Modified regular file a: 150 1 1: a 151 2 2: b 152 3 : c 153 [EOF] 154 "#); 155 let output = work_dir.run_jj(["show", "@++"]); 156 insta::assert_snapshot!(output, @r#" 157 Commit ID: d31d42e0267f6524d445348b1dd00926c62a6b57 158 Change ID: mouksmquosnpvwqrpsvvxtxpywpnxlss 159 Author : Test User <test.user@example.com> (2001-02-03 08:05:19) 160 Committer: Test User <test.user@example.com> (2001-02-03 08:05:19) 161 162 Back out "c" 163 164 This backs out commit 413337bbd11f7a6636c010d9e196acf801d8df2f. 165 166 Removed regular file b: 167 1 : b 168 [EOF] 169 "#); 170 let output = work_dir.run_jj(["show", "@+++"]); 171 insta::assert_snapshot!(output, @r#" 172 Commit ID: 6504c4ded177fba2334f76683d1aa643700d5073 173 Change ID: tqvpomtpwrqsylrpsxknultrymmqxmxv 174 Author : Test User <test.user@example.com> (2001-02-03 08:05:19) 175 Committer: Test User <test.user@example.com> (2001-02-03 08:05:19) 176 177 Back out "b" 178 179 This backs out commit 46cc97af6802301d8db381386e8485ff3ff24ae6. 180 181 Modified regular file a: 182 1 1: a 183 2 : b 184 [EOF] 185 "#); 186} 187 188#[test] 189fn test_backout_description_template() { 190 let test_env = TestEnvironment::default(); 191 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 192 test_env.add_config( 193 r#" 194 [templates] 195 backout_description = ''' 196 separate(" ", 197 "Revert commit", 198 commit_id.short(), 199 '"' ++ description.first_line() ++ '"', 200 ) 201 ''' 202 "#, 203 ); 204 let work_dir = test_env.work_dir("repo"); 205 create_commit_with_files(&work_dir, "a", &[], &[("a", "a\n")]); 206 207 // Test the setup 208 insta::assert_snapshot!(get_log_output(&work_dir), @r" 209 @ 2443ea76b0b1 a 210 ◆ 000000000000 211 [EOF] 212 "); 213 let output = work_dir.run_jj(["diff", "-s"]); 214 insta::assert_snapshot!(output, @r" 215 A a 216 [EOF] 217 "); 218 219 // Verify that message of backed out commit follows the template 220 let output = work_dir.run_jj(["backout", "-r", "a"]); 221 insta::assert_snapshot!(output, @r" 222 ------- stderr ------- 223 Warning: `jj backout` is deprecated; use `jj revert` instead 224 Warning: `jj backout` will be removed in a future version, and this will be a hard error 225 [EOF] 226 "); 227 insta::assert_snapshot!(get_log_output(&work_dir), @r#" 228 ○ 1db880a5204e Revert commit 2443ea76b0b1 "a" 229 @ 2443ea76b0b1 a 230 ◆ 000000000000 231 [EOF] 232 "#); 233} 234 235#[must_use] 236fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { 237 let template = r#"commit_id.short() ++ " " ++ description"#; 238 work_dir.run_jj(["log", "-T", template]) 239}