just playing with tangled
at ig/vimdiffwarn 321 lines 9.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 std::path::PathBuf; 16 17use test_case::test_case; 18 19use crate::common::create_commit; 20use crate::common::TestEnvironment; 21 22fn create_repo() -> (TestEnvironment, PathBuf) { 23 let test_env = TestEnvironment::default(); 24 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 25 let repo_path = test_env.env_root().join("repo"); 26 27 (test_env, repo_path) 28} 29 30#[test] 31fn test_simplify_parents_no_commits() { 32 let (test_env, repo_path) = create_repo(); 33 34 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-r", "root() ~ root()"]); 35 insta::assert_snapshot!(output, @r" 36 ------- stderr ------- 37 Nothing changed. 38 [EOF] 39 "); 40} 41 42#[test] 43fn test_simplify_parents_immutable() { 44 let (test_env, repo_path) = create_repo(); 45 46 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-r", "root()"]); 47 insta::assert_snapshot!(output, @r" 48 ------- stderr ------- 49 Error: The root commit 000000000000 is immutable 50 [EOF] 51 [exit status: 1] 52 "); 53} 54 55#[test] 56fn test_simplify_parents_no_change() { 57 let (test_env, repo_path) = create_repo(); 58 59 create_commit(&test_env.work_dir(&repo_path), "a", &["root()"]); 60 create_commit(&test_env.work_dir(&repo_path), "b", &["a"]); 61 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 62 insta::assert_snapshot!(output, @r" 63 @ b 64 ○ a 65 66 [EOF] 67 "); 68 69 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-s", "@-"]); 70 insta::assert_snapshot!(output, @r" 71 ------- stderr ------- 72 Nothing changed. 73 [EOF] 74 "); 75 76 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 77 insta::assert_snapshot!(output, @r" 78 @ b 79 ○ a 80 81 [EOF] 82 "); 83} 84 85#[test] 86fn test_simplify_parents_no_change_diamond() { 87 let (test_env, repo_path) = create_repo(); 88 89 create_commit(&test_env.work_dir(&repo_path), "a", &["root()"]); 90 create_commit(&test_env.work_dir(&repo_path), "b", &["a"]); 91 create_commit(&test_env.work_dir(&repo_path), "c", &["a"]); 92 create_commit(&test_env.work_dir(&repo_path), "d", &["b", "c"]); 93 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 94 insta::assert_snapshot!(output, @r" 95 @ d 96 ├─╮ 97 │ ○ c 98 ○ │ b 99 ├─╯ 100 ○ a 101102 [EOF] 103 "); 104 105 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-r", "all() ~ root()"]); 106 insta::assert_snapshot!(output, @r" 107 ------- stderr ------- 108 Nothing changed. 109 [EOF] 110 "); 111 112 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 113 insta::assert_snapshot!(output, @r" 114 @ d 115 ├─╮ 116 │ ○ c 117 ○ │ b 118 ├─╯ 119 ○ a 120121 [EOF] 122 "); 123} 124 125#[test_case(&["simplify-parents", "-r", "@", "-r", "@-"] ; "revisions")] 126#[test_case(&["simplify-parents", "-s", "@-"] ; "sources")] 127fn test_simplify_parents_redundant_parent(args: &[&str]) { 128 let (test_env, repo_path) = create_repo(); 129 130 create_commit(&test_env.work_dir(&repo_path), "a", &["root()"]); 131 create_commit(&test_env.work_dir(&repo_path), "b", &["a"]); 132 create_commit(&test_env.work_dir(&repo_path), "c", &["a", "b"]); 133 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 134 insta::allow_duplicates! { 135 insta::assert_snapshot!(output, @r" 136 @ c 137 ├─╮ 138 │ ○ b 139 ├─╯ 140 ○ a 141142 [EOF] 143 "); 144 } 145 let output = test_env.run_jj_in(&repo_path, args); 146 insta::allow_duplicates! { 147 insta::assert_snapshot!(output, @r" 148 ------- stderr ------- 149 Removed 1 edges from 1 out of 3 commits. 150 Working copy (@) now at: royxmykx 0ac2063b c | c 151 Parent commit (@-) : zsuskuln 1394f625 b | b 152 [EOF] 153 "); 154 } 155 156 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 157 insta::allow_duplicates! { 158 insta::assert_snapshot!(output, @r" 159 @ c 160 ○ b 161 ○ a 162163 [EOF] 164 "); 165 } 166} 167 168#[test] 169fn test_simplify_parents_multiple_redundant_parents() { 170 let (test_env, repo_path) = create_repo(); 171 172 create_commit(&test_env.work_dir(&repo_path), "a", &["root()"]); 173 create_commit(&test_env.work_dir(&repo_path), "b", &["a"]); 174 create_commit(&test_env.work_dir(&repo_path), "c", &["a", "b"]); 175 create_commit(&test_env.work_dir(&repo_path), "d", &["c"]); 176 create_commit(&test_env.work_dir(&repo_path), "e", &["d"]); 177 create_commit(&test_env.work_dir(&repo_path), "f", &["d", "e"]); 178 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 179 insta::assert_snapshot!(output, @r" 180 @ f 181 ├─╮ 182 │ ○ e 183 ├─╯ 184 ○ d 185 ○ c 186 ├─╮ 187 │ ○ b 188 ├─╯ 189 ○ a 190191 [EOF] 192 "); 193 let setup_opid = test_env.work_dir(&repo_path).current_operation_id(); 194 195 // Test with `-r`. 196 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-r", "c", "-r", "f"]); 197 insta::assert_snapshot!(output, @r" 198 ------- stderr ------- 199 Removed 2 edges from 2 out of 2 commits. 200 Rebased 2 descendant commits 201 Working copy (@) now at: kmkuslsw 8cc01e1b f | f 202 Parent commit (@-) : znkkpsqq 040ae3a6 e | e 203 [EOF] 204 "); 205 206 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 207 insta::assert_snapshot!(output, @r" 208 @ f 209 ○ e 210 ○ d 211 ○ c 212 ○ b 213 ○ a 214215 [EOF] 216 "); 217 218 // Test with `-s`. 219 test_env 220 .run_jj_in(&repo_path, ["op", "restore", &setup_opid]) 221 .success(); 222 let output = test_env.run_jj_in(&repo_path, ["simplify-parents", "-s", "c"]); 223 insta::assert_snapshot!(output, @r" 224 ------- stderr ------- 225 Removed 2 edges from 2 out of 4 commits. 226 Rebased 2 descendant commits 227 Working copy (@) now at: kmkuslsw 70a39dff f | f 228 Parent commit (@-) : znkkpsqq a021fee9 e | e 229 [EOF] 230 "); 231 232 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 233 insta::assert_snapshot!(output, @r" 234 @ f 235 ○ e 236 ○ d 237 ○ c 238 ○ b 239 ○ a 240241 [EOF] 242 "); 243} 244 245#[test] 246fn test_simplify_parents_no_args() { 247 let (test_env, repo_path) = create_repo(); 248 249 create_commit(&test_env.work_dir(&repo_path), "a", &["root()"]); 250 create_commit(&test_env.work_dir(&repo_path), "b", &["a"]); 251 create_commit(&test_env.work_dir(&repo_path), "c", &["a", "b"]); 252 create_commit(&test_env.work_dir(&repo_path), "d", &["c"]); 253 create_commit(&test_env.work_dir(&repo_path), "e", &["d"]); 254 create_commit(&test_env.work_dir(&repo_path), "f", &["d", "e"]); 255 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 256 insta::assert_snapshot!(output, @r" 257 @ f 258 ├─╮ 259 │ ○ e 260 ├─╯ 261 ○ d 262 ○ c 263 ├─╮ 264 │ ○ b 265 ├─╯ 266 ○ a 267268 [EOF] 269 "); 270 let setup_opid = test_env.work_dir(&repo_path).current_operation_id(); 271 272 let output = test_env.run_jj_in(&repo_path, ["simplify-parents"]); 273 insta::assert_snapshot!(output, @r" 274 ------- stderr ------- 275 Removed 2 edges from 2 out of 6 commits. 276 Rebased 2 descendant commits 277 Working copy (@) now at: kmkuslsw 8cc01e1b f | f 278 Parent commit (@-) : znkkpsqq 040ae3a6 e | e 279 [EOF] 280 "); 281 282 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 283 insta::assert_snapshot!(output, @r" 284 @ f 285 ○ e 286 ○ d 287 ○ c 288 ○ b 289 ○ a 290291 [EOF] 292 "); 293 294 // Test with custom `revsets.simplify-parents`. 295 test_env 296 .run_jj_in(&repo_path, ["op", "restore", &setup_opid]) 297 .success(); 298 test_env.add_config(r#"revsets.simplify-parents = "d::""#); 299 let output = test_env.run_jj_in(&repo_path, ["simplify-parents"]); 300 insta::assert_snapshot!(output, @r" 301 ------- stderr ------- 302 Removed 1 edges from 1 out of 3 commits. 303 Working copy (@) now at: kmkuslsw 0c6b4c43 f | f 304 Parent commit (@-) : znkkpsqq 6a679611 e | e 305 [EOF] 306 "); 307 308 let output = test_env.run_jj_in(&repo_path, ["log", "-r", "all()", "-T", "description"]); 309 insta::assert_snapshot!(output, @r" 310 @ f 311 ○ e 312 ○ d 313 ○ c 314 ├─╮ 315 │ ○ b 316 ├─╯ 317 ○ a 318319 [EOF] 320 "); 321}