| 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 crate::common::CommandOutput; |
| 16 |
use crate::common::TestEnvironment; |
| 17 |
use crate::common::TestWorkDir; |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn test_parallelize_no_descendants() { |
| 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 |
for n in 1..6 { |
| 26 |
work_dir.run_jj(["commit", &format!("-m{n}")]).success(); |
| 27 |
} |
| 28 |
work_dir.run_jj(["describe", "-m=6"]).success(); |
| 29 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 30 |
@ e12cca0818cd 6 parents: 5 |
| 31 |
○ 44f4686efbe9 5 parents: 4 |
| 32 |
○ 6858f6e16a6c 4 parents: 3 |
| 33 |
○ 8cfb27e238c8 3 parents: 2 |
| 34 |
○ 320daf48ba58 2 parents: 1 |
| 35 |
○ 884fe9b9c656 1 parents: |
| 36 |
◆ 000000000000 parents: |
| 37 |
[EOF] |
| 38 |
"); |
| 39 |
|
| 40 |
work_dir.run_jj(["parallelize", "subject(1)::"]).success(); |
| 41 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 42 |
@ 22b8a32d1949 6 parents: |
| 43 |
│ ○ 436e81ced43f 5 parents: |
| 44 |
├─╯ |
| 45 |
│ ○ 823bf930aefb 4 parents: |
| 46 |
├─╯ |
| 47 |
│ ○ 3b6586259aa9 3 parents: |
| 48 |
├─╯ |
| 49 |
│ ○ dfd927ce07c0 2 parents: |
| 50 |
├─╯ |
| 51 |
│ ○ 884fe9b9c656 1 parents: |
| 52 |
├─╯ |
| 53 |
◆ 000000000000 parents: |
| 54 |
[EOF] |
| 55 |
"); |
| 56 |
} |
| 57 |
|
| 58 |
// Only the head commit has descendants. |
| 59 |
#[test] |
| 60 |
fn test_parallelize_with_descendants_simple() { |
| 61 |
let test_env = TestEnvironment::default(); |
| 62 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 63 |
let work_dir = test_env.work_dir("repo"); |
| 64 |
|
| 65 |
for n in 1..6 { |
| 66 |
work_dir.run_jj(["commit", &format!("-m{n}")]).success(); |
| 67 |
} |
| 68 |
work_dir.run_jj(["describe", "-m=6"]).success(); |
| 69 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 70 |
@ e12cca0818cd 6 parents: 5 |
| 71 |
○ 44f4686efbe9 5 parents: 4 |
| 72 |
○ 6858f6e16a6c 4 parents: 3 |
| 73 |
○ 8cfb27e238c8 3 parents: 2 |
| 74 |
○ 320daf48ba58 2 parents: 1 |
| 75 |
○ 884fe9b9c656 1 parents: |
| 76 |
◆ 000000000000 parents: |
| 77 |
[EOF] |
| 78 |
"); |
| 79 |
|
| 80 |
work_dir |
| 81 |
.run_jj(["parallelize", "subject(1)::subject(4)"]) |
| 82 |
.success(); |
| 83 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 84 |
@ 75ac07d7dedc 6 parents: 5 |
| 85 |
○ 39791a4c42c5 5 parents: 1 2 3 4 |
| 86 |
├─┬─┬─╮ |
| 87 |
│ │ │ ○ 823bf930aefb 4 parents: |
| 88 |
│ │ ○ │ 3b6586259aa9 3 parents: |
| 89 |
│ │ ├─╯ |
| 90 |
│ ○ │ dfd927ce07c0 2 parents: |
| 91 |
│ ├─╯ |
| 92 |
○ │ 884fe9b9c656 1 parents: |
| 93 |
├─╯ |
| 94 |
◆ 000000000000 parents: |
| 95 |
[EOF] |
| 96 |
"); |
| 97 |
} |
| 98 |
|
| 99 |
// One of the commits being parallelized has a child that isn't being |
| 100 |
// parallelized. That child will become a merge of any ancestors which are being |
| 101 |
// parallelized. |
| 102 |
#[test] |
| 103 |
fn test_parallelize_where_interior_has_non_target_children() { |
| 104 |
let test_env = TestEnvironment::default(); |
| 105 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 106 |
let work_dir = test_env.work_dir("repo"); |
| 107 |
|
| 108 |
for n in 1..6 { |
| 109 |
work_dir.run_jj(["commit", &format!("-m{n}")]).success(); |
| 110 |
} |
| 111 |
work_dir.run_jj(["new", "subject(2)", "-m=2c"]).success(); |
| 112 |
work_dir.run_jj(["new", "subject(5)", "-m=6"]).success(); |
| 113 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 114 |
@ 9554e07afe42 6 parents: 5 |
| 115 |
○ 44f4686efbe9 5 parents: 4 |
| 116 |
○ 6858f6e16a6c 4 parents: 3 |
| 117 |
○ 8cfb27e238c8 3 parents: 2 |
| 118 |
│ ○ a5a460ad9943 2c parents: 2 |
| 119 |
├─╯ |
| 120 |
○ 320daf48ba58 2 parents: 1 |
| 121 |
○ 884fe9b9c656 1 parents: |
| 122 |
◆ 000000000000 parents: |
| 123 |
[EOF] |
| 124 |
"); |
| 125 |
|
| 126 |
work_dir |
| 127 |
.run_jj(["parallelize", "subject(1)::subject(4)"]) |
| 128 |
.success(); |
| 129 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 130 |
@ 8bbff9ba415a 6 parents: 5 |
| 131 |
○ 3bfb6f7542f6 5 parents: 1 2 3 4 |
| 132 |
├─┬─┬─╮ |
| 133 |
│ │ │ ○ 486dfbb53401 4 parents: |
| 134 |
│ │ ○ │ 71c114f0dd4d 3 parents: |
| 135 |
│ │ ├─╯ |
| 136 |
│ │ │ ○ 154d3801414a 2c parents: 1 2 |
| 137 |
╭─┬───╯ |
| 138 |
│ ○ │ 7c8f6e529b52 2 parents: |
| 139 |
│ ├─╯ |
| 140 |
○ │ 884fe9b9c656 1 parents: |
| 141 |
├─╯ |
| 142 |
◆ 000000000000 parents: |
| 143 |
[EOF] |
| 144 |
"); |
| 145 |
} |
| 146 |
|
| 147 |
#[test] |
| 148 |
fn test_parallelize_where_root_has_non_target_children() { |
| 149 |
let test_env = TestEnvironment::default(); |
| 150 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 151 |
let work_dir = test_env.work_dir("repo"); |
| 152 |
|
| 153 |
for n in 1..4 { |
| 154 |
work_dir.run_jj(["commit", &format!("-m{n}")]).success(); |
| 155 |
} |
| 156 |
work_dir.run_jj(["new", "subject(1)", "-m=1c"]).success(); |
| 157 |
work_dir.run_jj(["new", "subject(3)", "-m=4"]).success(); |
| 158 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 159 |
@ 4c392c2965f0 4 parents: 3 |
| 160 |
○ 8cfb27e238c8 3 parents: 2 |
| 161 |
○ 320daf48ba58 2 parents: 1 |
| 162 |
│ ○ 2935e6f82e54 1c parents: 1 |
| 163 |
├─╯ |
| 164 |
○ 884fe9b9c656 1 parents: |
| 165 |
◆ 000000000000 parents: |
| 166 |
[EOF] |
| 167 |
"); |
| 168 |
work_dir |
| 169 |
.run_jj(["parallelize", "subject(1)::subject(3)"]) |
| 170 |
.success(); |
| 171 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 172 |
@ a5d4e90a54bf 4 parents: 1 2 3 |
| 173 |
├─┬─╮ |
| 174 |
│ │ ○ 1d9fa9e05929 3 parents: |
| 175 |
│ ○ │ f773cf087413 2 parents: |
| 176 |
│ ├─╯ |
| 177 |
│ │ ○ 2935e6f82e54 1c parents: 1 |
| 178 |
├───╯ |
| 179 |
○ │ 884fe9b9c656 1 parents: |
| 180 |
├─╯ |
| 181 |
◆ 000000000000 parents: |
| 182 |
[EOF] |
| 183 |
"); |
| 184 |
} |
| 185 |
|
| 186 |
// One of the commits being parallelized has a child that is a merge commit. |
| 187 |
#[test] |
| 188 |
fn test_parallelize_with_merge_commit_child() { |
| 189 |
let test_env = TestEnvironment::default(); |
| 190 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 191 |
let work_dir = test_env.work_dir("repo"); |
| 192 |
|
| 193 |
work_dir.run_jj(["commit", "-m", "1"]).success(); |
| 194 |
for n in 2..4 { |
| 195 |
work_dir.run_jj(["commit", "-m", &n.to_string()]).success(); |
| 196 |
} |
| 197 |
work_dir.run_jj(["new", "root()", "-m", "a"]).success(); |
| 198 |
work_dir |
| 199 |
.run_jj(["new", "subject(2)", "subject(a)", "-m", "2a-c"]) |
| 200 |
.success(); |
| 201 |
work_dir.run_jj(["new", "subject(3)", "-m", "4"]).success(); |
| 202 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 203 |
@ e6a543fcc5d8 4 parents: 3 |
| 204 |
○ 8cfb27e238c8 3 parents: 2 |
| 205 |
│ ○ af7ad8059bf1 2a-c parents: 2 a |
| 206 |
╭─┤ |
| 207 |
│ ○ 8fa549442479 a parents: |
| 208 |
○ │ 320daf48ba58 2 parents: 1 |
| 209 |
○ │ 884fe9b9c656 1 parents: |
| 210 |
├─╯ |
| 211 |
◆ 000000000000 parents: |
| 212 |
[EOF] |
| 213 |
"); |
| 214 |
|
| 215 |
// After this finishes, child-2a will have three parents: "1", "2", and "a". |
| 216 |
work_dir |
| 217 |
.run_jj(["parallelize", "subject(1)::subject(3)"]) |
| 218 |
.success(); |
| 219 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 220 |
@ 431d5005bab0 4 parents: 1 2 3 |
| 221 |
├─┬─╮ |
| 222 |
│ │ ○ 3b6586259aa9 3 parents: |
| 223 |
│ │ │ ○ 67b28b5cc688 2a-c parents: 1 2 a |
| 224 |
╭─┬───┤ |
| 225 |
│ │ │ ○ 8fa549442479 a parents: |
| 226 |
│ │ ├─╯ |
| 227 |
│ ○ │ dfd927ce07c0 2 parents: |
| 228 |
│ ├─╯ |
| 229 |
○ │ 884fe9b9c656 1 parents: |
| 230 |
├─╯ |
| 231 |
◆ 000000000000 parents: |
| 232 |
[EOF] |
| 233 |
"); |
| 234 |
} |
| 235 |
|
| 236 |
#[test] |
| 237 |
fn test_parallelize_disconnected_target_commits() { |
| 238 |
let test_env = TestEnvironment::default(); |
| 239 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 240 |
let work_dir = test_env.work_dir("repo"); |
| 241 |
|
| 242 |
for n in 1..3 { |
| 243 |
work_dir.run_jj(["commit", &format!("-m{n}")]).success(); |
| 244 |
} |
| 245 |
work_dir.run_jj(["describe", "-m=3"]).success(); |
| 246 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 247 |
@ 8cfb27e238c8 3 parents: 2 |
| 248 |
○ 320daf48ba58 2 parents: 1 |
| 249 |
○ 884fe9b9c656 1 parents: |
| 250 |
◆ 000000000000 parents: |
| 251 |
[EOF] |
| 252 |
"); |
| 253 |
|
| 254 |
let output = work_dir.run_jj(["parallelize", "subject(1)", "-r=subject(3)"]); |
| 255 |
insta::assert_snapshot!(output, @" |
| 256 |
------- stderr ------- |
| 257 |
Nothing changed. |
| 258 |
[EOF] |
| 259 |
"); |
| 260 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 261 |
@ 8cfb27e238c8 3 parents: 2 |
| 262 |
○ 320daf48ba58 2 parents: 1 |
| 263 |
○ 884fe9b9c656 1 parents: |
| 264 |
◆ 000000000000 parents: |
| 265 |
[EOF] |
| 266 |
"); |
| 267 |
} |
| 268 |
|
| 269 |
#[test] |
| 270 |
fn test_parallelize_head_is_a_merge() { |
| 271 |
let test_env = TestEnvironment::default(); |
| 272 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 273 |
let work_dir = test_env.work_dir("repo"); |
| 274 |
work_dir.run_jj(["commit", "-m=0"]).success(); |
| 275 |
work_dir.run_jj(["commit", "-m=1"]).success(); |
| 276 |
work_dir.run_jj(["commit", "-m=2"]).success(); |
| 277 |
work_dir.run_jj(["new", "root()"]).success(); |
| 278 |
work_dir.run_jj(["commit", "-m=a"]).success(); |
| 279 |
work_dir.run_jj(["commit", "-m=b"]).success(); |
| 280 |
work_dir |
| 281 |
.run_jj(["new", "subject(2)", "subject(b)", "-m=merged-head"]) |
| 282 |
.success(); |
| 283 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 284 |
@ c634925e6ac2 merged-head parents: 2 b |
| 285 |
├─╮ |
| 286 |
│ ○ 448c6310957c b parents: a |
| 287 |
│ ○ 07fb6466f0cd a parents: |
| 288 |
○ │ 1ae5c538c8ef 2 parents: 1 |
| 289 |
○ │ 42fc76489fb1 1 parents: 0 |
| 290 |
○ │ fc8a812f1b99 0 parents: |
| 291 |
├─╯ |
| 292 |
◆ 000000000000 parents: |
| 293 |
[EOF] |
| 294 |
"); |
| 295 |
|
| 296 |
work_dir.run_jj(["parallelize", "subject(1)::"]).success(); |
| 297 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 298 |
@ f97b547cdca0 merged-head parents: 0 b |
| 299 |
├─╮ |
| 300 |
│ ○ 448c6310957c b parents: a |
| 301 |
│ ○ 07fb6466f0cd a parents: |
| 302 |
│ │ ○ b240f5a52f77 2 parents: 0 |
| 303 |
├───╯ |
| 304 |
│ │ ○ 42fc76489fb1 1 parents: 0 |
| 305 |
├───╯ |
| 306 |
○ │ fc8a812f1b99 0 parents: |
| 307 |
├─╯ |
| 308 |
◆ 000000000000 parents: |
| 309 |
[EOF] |
| 310 |
"); |
| 311 |
} |
| 312 |
|
| 313 |
#[test] |
| 314 |
fn test_parallelize_interior_target_is_a_merge() { |
| 315 |
let test_env = TestEnvironment::default(); |
| 316 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 317 |
let work_dir = test_env.work_dir("repo"); |
| 318 |
work_dir.run_jj(["commit", "-m=0"]).success(); |
| 319 |
work_dir.run_jj(["describe", "-m=1"]).success(); |
| 320 |
work_dir.run_jj(["new", "root()", "-m=a"]).success(); |
| 321 |
work_dir |
| 322 |
.run_jj(["new", "subject(1)", "subject(a)", "-m=2"]) |
| 323 |
.success(); |
| 324 |
work_dir.run_jj(["new", "-m=3"]).success(); |
| 325 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 326 |
@ d84d604297c3 3 parents: 2 |
| 327 |
○ 5684656729e6 2 parents: 1 a |
| 328 |
├─╮ |
| 329 |
│ ○ 55fc07cbd79b a parents: |
| 330 |
○ │ 42fc76489fb1 1 parents: 0 |
| 331 |
○ │ fc8a812f1b99 0 parents: |
| 332 |
├─╯ |
| 333 |
◆ 000000000000 parents: |
| 334 |
[EOF] |
| 335 |
"); |
| 336 |
|
| 337 |
work_dir.run_jj(["parallelize", "subject(1)::"]).success(); |
| 338 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 339 |
@ d0dae190124d 3 parents: 0 a |
| 340 |
├─╮ |
| 341 |
│ │ ○ d5756d591190 2 parents: 0 a |
| 342 |
╭─┬─╯ |
| 343 |
│ ○ 55fc07cbd79b a parents: |
| 344 |
│ │ ○ 42fc76489fb1 1 parents: 0 |
| 345 |
├───╯ |
| 346 |
○ │ fc8a812f1b99 0 parents: |
| 347 |
├─╯ |
| 348 |
◆ 000000000000 parents: |
| 349 |
[EOF] |
| 350 |
"); |
| 351 |
} |
| 352 |
|
| 353 |
#[test] |
| 354 |
fn test_parallelize_root_is_a_merge() { |
| 355 |
let test_env = TestEnvironment::default(); |
| 356 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 357 |
let work_dir = test_env.work_dir("repo"); |
| 358 |
work_dir.run_jj(["describe", "-m=y"]).success(); |
| 359 |
work_dir.run_jj(["new", "root()", "-m=x"]).success(); |
| 360 |
work_dir |
| 361 |
.run_jj(["new", "subject(y)", "subject(x)", "-m=1"]) |
| 362 |
.success(); |
| 363 |
work_dir.run_jj(["new", "-m=2"]).success(); |
| 364 |
work_dir.run_jj(["new", "-m=3"]).success(); |
| 365 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 366 |
@ ce0ec2d2d844 3 parents: 2 |
| 367 |
○ 44681d919431 2 parents: 1 |
| 368 |
○ 8a06bcc06aad 1 parents: y x |
| 369 |
├─╮ |
| 370 |
│ ○ 2d5d6dbc7e1f x parents: |
| 371 |
○ │ 1ecf47f2262c y parents: |
| 372 |
├─╯ |
| 373 |
◆ 000000000000 parents: |
| 374 |
[EOF] |
| 375 |
"); |
| 376 |
|
| 377 |
work_dir |
| 378 |
.run_jj(["parallelize", "subject(1)::subject(2)"]) |
| 379 |
.success(); |
| 380 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 381 |
@ 2949bc60f108 3 parents: 1 2 |
| 382 |
├─╮ |
| 383 |
│ ○ bf222a0e51d4 2 parents: y x |
| 384 |
│ ├─╮ |
| 385 |
○ │ │ 8a06bcc06aad 1 parents: y x |
| 386 |
╰─┬─╮ |
| 387 |
│ ○ 2d5d6dbc7e1f x parents: |
| 388 |
○ │ 1ecf47f2262c y parents: |
| 389 |
├─╯ |
| 390 |
◆ 000000000000 parents: |
| 391 |
[EOF] |
| 392 |
"); |
| 393 |
} |
| 394 |
|
| 395 |
#[test] |
| 396 |
fn test_parallelize_multiple_heads() { |
| 397 |
let test_env = TestEnvironment::default(); |
| 398 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 399 |
let work_dir = test_env.work_dir("repo"); |
| 400 |
work_dir.run_jj(["commit", "-m=0"]).success(); |
| 401 |
work_dir.run_jj(["describe", "-m=1"]).success(); |
| 402 |
work_dir.run_jj(["new", "subject(0)", "-m=2"]).success(); |
| 403 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 404 |
@ 96d58e6cf428 2 parents: 0 |
| 405 |
│ ○ 42fc76489fb1 1 parents: 0 |
| 406 |
├─╯ |
| 407 |
○ fc8a812f1b99 0 parents: |
| 408 |
◆ 000000000000 parents: |
| 409 |
[EOF] |
| 410 |
"); |
| 411 |
|
| 412 |
work_dir.run_jj(["parallelize", "subject(0)::"]).success(); |
| 413 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 414 |
@ fefea56b23ab 2 parents: |
| 415 |
│ ○ c4b1ea1106d1 1 parents: |
| 416 |
├─╯ |
| 417 |
│ ○ fc8a812f1b99 0 parents: |
| 418 |
├─╯ |
| 419 |
◆ 000000000000 parents: |
| 420 |
[EOF] |
| 421 |
"); |
| 422 |
} |
| 423 |
|
| 424 |
// All heads must have the same children as the other heads, but only if they |
| 425 |
// have children. In this test only one head has children, so the command |
| 426 |
// succeeds. |
| 427 |
#[test] |
| 428 |
fn test_parallelize_multiple_heads_with_and_without_children() { |
| 429 |
let test_env = TestEnvironment::default(); |
| 430 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 431 |
let work_dir = test_env.work_dir("repo"); |
| 432 |
work_dir.run_jj(["commit", "-m=0"]).success(); |
| 433 |
work_dir.run_jj(["describe", "-m=1"]).success(); |
| 434 |
work_dir.run_jj(["new", "subject(0)", "-m=2"]).success(); |
| 435 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 436 |
@ 96d58e6cf428 2 parents: 0 |
| 437 |
│ ○ 42fc76489fb1 1 parents: 0 |
| 438 |
├─╯ |
| 439 |
○ fc8a812f1b99 0 parents: |
| 440 |
◆ 000000000000 parents: |
| 441 |
[EOF] |
| 442 |
"); |
| 443 |
|
| 444 |
work_dir |
| 445 |
.run_jj(["parallelize", "-r=subject(0)", "subject(1)"]) |
| 446 |
.success(); |
| 447 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 448 |
@ 96d58e6cf428 2 parents: 0 |
| 449 |
○ fc8a812f1b99 0 parents: |
| 450 |
│ ○ c4b1ea1106d1 1 parents: |
| 451 |
├─╯ |
| 452 |
◆ 000000000000 parents: |
| 453 |
[EOF] |
| 454 |
"); |
| 455 |
} |
| 456 |
|
| 457 |
#[test] |
| 458 |
fn test_parallelize_multiple_roots() { |
| 459 |
let test_env = TestEnvironment::default(); |
| 460 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 461 |
let work_dir = test_env.work_dir("repo"); |
| 462 |
work_dir.run_jj(["describe", "-m=1"]).success(); |
| 463 |
work_dir.run_jj(["new", "root()", "-m=a"]).success(); |
| 464 |
work_dir |
| 465 |
.run_jj(["new", "subject(1)", "subject(a)", "-m=2"]) |
| 466 |
.success(); |
| 467 |
work_dir.run_jj(["new", "-m=3"]).success(); |
| 468 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 469 |
@ 9653da1c76e9 3 parents: 2 |
| 470 |
○ 248a57e1c968 2 parents: 1 a |
| 471 |
├─╮ |
| 472 |
│ ○ 3ce82963438f a parents: |
| 473 |
○ │ 884fe9b9c656 1 parents: |
| 474 |
├─╯ |
| 475 |
◆ 000000000000 parents: |
| 476 |
[EOF] |
| 477 |
"); |
| 478 |
|
| 479 |
// Succeeds because the roots have the same parents. |
| 480 |
work_dir.run_jj(["parallelize", "root().."]).success(); |
| 481 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 482 |
@ 0c77dac691b5 3 parents: |
| 483 |
│ ○ 1a23775d87d5 2 parents: |
| 484 |
├─╯ |
| 485 |
│ ○ 3ce82963438f a parents: |
| 486 |
├─╯ |
| 487 |
│ ○ 884fe9b9c656 1 parents: |
| 488 |
├─╯ |
| 489 |
◆ 000000000000 parents: |
| 490 |
[EOF] |
| 491 |
"); |
| 492 |
} |
| 493 |
|
| 494 |
#[test] |
| 495 |
fn test_parallelize_multiple_heads_with_different_children() { |
| 496 |
let test_env = TestEnvironment::default(); |
| 497 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 498 |
let work_dir = test_env.work_dir("repo"); |
| 499 |
work_dir.run_jj(["commit", "-m=1"]).success(); |
| 500 |
work_dir.run_jj(["commit", "-m=2"]).success(); |
| 501 |
work_dir.run_jj(["commit", "-m=3"]).success(); |
| 502 |
work_dir.run_jj(["new", "root()"]).success(); |
| 503 |
work_dir.run_jj(["commit", "-m=a"]).success(); |
| 504 |
work_dir.run_jj(["commit", "-m=b"]).success(); |
| 505 |
work_dir.run_jj(["commit", "-m=c"]).success(); |
| 506 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 507 |
@ afa59494cb01 parents: c |
| 508 |
○ 8897bad1837f c parents: b |
| 509 |
○ 448c6310957c b parents: a |
| 510 |
○ 07fb6466f0cd a parents: |
| 511 |
│ ○ 8cfb27e238c8 3 parents: 2 |
| 512 |
│ ○ 320daf48ba58 2 parents: 1 |
| 513 |
│ ○ 884fe9b9c656 1 parents: |
| 514 |
├─╯ |
| 515 |
◆ 000000000000 parents: |
| 516 |
[EOF] |
| 517 |
"); |
| 518 |
|
| 519 |
work_dir |
| 520 |
.run_jj([ |
| 521 |
"parallelize", |
| 522 |
"subject(1)::subject(2)", |
| 523 |
"subject(a)::subject(b)", |
| 524 |
]) |
| 525 |
.success(); |
| 526 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 527 |
@ 7d3e76dfbc7b parents: c |
| 528 |
○ 6dbfcf648fad c parents: a b |
| 529 |
├─╮ |
| 530 |
│ ○ 8e5c55acd419 b parents: |
| 531 |
○ │ 07fb6466f0cd a parents: |
| 532 |
├─╯ |
| 533 |
│ ○ abdef66ee7e9 3 parents: 1 2 |
| 534 |
│ ├─╮ |
| 535 |
│ │ ○ 7c8f6e529b52 2 parents: |
| 536 |
├───╯ |
| 537 |
│ ○ 884fe9b9c656 1 parents: |
| 538 |
├─╯ |
| 539 |
◆ 000000000000 parents: |
| 540 |
[EOF] |
| 541 |
"); |
| 542 |
} |
| 543 |
|
| 544 |
#[test] |
| 545 |
fn test_parallelize_multiple_roots_with_different_parents() { |
| 546 |
let test_env = TestEnvironment::default(); |
| 547 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 548 |
let work_dir = test_env.work_dir("repo"); |
| 549 |
work_dir.run_jj(["commit", "-m=1"]).success(); |
| 550 |
work_dir.run_jj(["commit", "-m=2"]).success(); |
| 551 |
work_dir.run_jj(["new", "root()"]).success(); |
| 552 |
work_dir.run_jj(["commit", "-m=a"]).success(); |
| 553 |
work_dir.run_jj(["commit", "-m=b"]).success(); |
| 554 |
work_dir |
| 555 |
.run_jj(["new", "subject(2)", "subject(b)", "-m=merged-head"]) |
| 556 |
.success(); |
| 557 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 558 |
@ 4e5f16f52b5e merged-head parents: 2 b |
| 559 |
├─╮ |
| 560 |
│ ○ 7686d0ce4f97 b parents: a |
| 561 |
│ ○ 331119737aad a parents: |
| 562 |
○ │ 320daf48ba58 2 parents: 1 |
| 563 |
○ │ 884fe9b9c656 1 parents: |
| 564 |
├─╯ |
| 565 |
◆ 000000000000 parents: |
| 566 |
[EOF] |
| 567 |
"); |
| 568 |
|
| 569 |
work_dir |
| 570 |
.run_jj(["parallelize", "subject(2)::", "subject(b)::"]) |
| 571 |
.success(); |
| 572 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 573 |
@ 180840c2f967 merged-head parents: 1 a |
| 574 |
├─╮ |
| 575 |
│ │ ○ 7686d0ce4f97 b parents: a |
| 576 |
│ ├─╯ |
| 577 |
│ ○ 331119737aad a parents: |
| 578 |
│ │ ○ 320daf48ba58 2 parents: 1 |
| 579 |
├───╯ |
| 580 |
○ │ 884fe9b9c656 1 parents: |
| 581 |
├─╯ |
| 582 |
◆ 000000000000 parents: |
| 583 |
[EOF] |
| 584 |
"); |
| 585 |
} |
| 586 |
|
| 587 |
#[test] |
| 588 |
fn test_parallelize_complex_nonlinear_target() { |
| 589 |
let test_env = TestEnvironment::default(); |
| 590 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 591 |
let work_dir = test_env.work_dir("repo"); |
| 592 |
work_dir.run_jj(["new", "-m=0", "root()"]).success(); |
| 593 |
work_dir.run_jj(["new", "-m=1", "subject(0)"]).success(); |
| 594 |
work_dir.run_jj(["new", "-m=2", "subject(0)"]).success(); |
| 595 |
work_dir.run_jj(["new", "-m=3", "subject(0)"]).success(); |
| 596 |
work_dir.run_jj(["new", "-m=4", "heads(..)"]).success(); |
| 597 |
work_dir.run_jj(["new", "-m=1c", "subject(1)"]).success(); |
| 598 |
work_dir.run_jj(["new", "-m=2c", "subject(2)"]).success(); |
| 599 |
work_dir.run_jj(["new", "-m=3c", "subject(3)"]).success(); |
| 600 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 601 |
@ 5cca06f145b2 3c parents: 3 |
| 602 |
│ ○ 095be6de6f23 4 parents: 3 2 1 |
| 603 |
╭─┼─╮ |
| 604 |
○ │ │ 46cc2c450bba 3 parents: 0 |
| 605 |
│ │ │ ○ 24113692de1e 2c parents: 2 |
| 606 |
│ ├───╯ |
| 607 |
│ ○ │ 5664a1d6ac8f 2 parents: 0 |
| 608 |
├─╯ │ |
| 609 |
│ ○ │ 6d578e6cbc1a 1c parents: 1 |
| 610 |
│ ├─╯ |
| 611 |
│ ○ 883b398bc1fd 1 parents: 0 |
| 612 |
├─╯ |
| 613 |
○ 973f85cf2550 0 parents: |
| 614 |
◆ 000000000000 parents: |
| 615 |
[EOF] |
| 616 |
"); |
| 617 |
|
| 618 |
let output = work_dir.run_jj(["parallelize", "subject(0)::subject(4)"]); |
| 619 |
insta::assert_snapshot!(output, @" |
| 620 |
------- stderr ------- |
| 621 |
Working copy (@) now at: yostqsxw d6bb6520 (empty) 3c |
| 622 |
Parent commit (@-) : rlvkpnrz 973f85cf (empty) 0 |
| 623 |
Parent commit (@-) : mzvwutvl 47ec86fe (empty) 3 |
| 624 |
[EOF] |
| 625 |
"); |
| 626 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 627 |
@ d6bb652004e4 3c parents: 0 3 |
| 628 |
├─╮ |
| 629 |
│ ○ 47ec86fe7334 3 parents: |
| 630 |
│ │ ○ 79e22ba7b736 2c parents: 0 2 |
| 631 |
╭───┤ |
| 632 |
│ │ ○ 9d6818f73e0d 2 parents: |
| 633 |
│ ├─╯ |
| 634 |
│ │ ○ bbeb29b59bee 1c parents: 0 1 |
| 635 |
╭───┤ |
| 636 |
│ │ ○ ea96e6d5bb04 1 parents: |
| 637 |
│ ├─╯ |
| 638 |
○ │ 973f85cf2550 0 parents: |
| 639 |
├─╯ |
| 640 |
│ ○ 0f9aae95edbe 4 parents: |
| 641 |
├─╯ |
| 642 |
◆ 000000000000 parents: |
| 643 |
[EOF] |
| 644 |
"); |
| 645 |
} |
| 646 |
|
| 647 |
#[test] |
| 648 |
fn test_parallelize_immutable_base_commits() { |
| 649 |
let test_env = TestEnvironment::default(); |
| 650 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 651 |
let work_dir = test_env.work_dir("repo"); |
| 652 |
|
| 653 |
work_dir.run_jj(["new", "root()", "-m=x"]).success(); |
| 654 |
work_dir.run_jj(["new", "-m=x1"]).success(); |
| 655 |
work_dir.run_jj(["new", "-m=x2"]).success(); |
| 656 |
work_dir.run_jj(["new", "-m=x3"]).success(); |
| 657 |
|
| 658 |
work_dir.run_jj(["new", "root()", "-m=y"]).success(); |
| 659 |
work_dir.run_jj(["new", "-m=y1"]).success(); |
| 660 |
work_dir.run_jj(["new", "-m=y2"]).success(); |
| 661 |
|
| 662 |
work_dir |
| 663 |
.run_jj([ |
| 664 |
"config", |
| 665 |
"set", |
| 666 |
"--repo", |
| 667 |
"revset-aliases.'immutable_heads()'", |
| 668 |
"subject(x) | subject(y)", |
| 669 |
]) |
| 670 |
.success(); |
| 671 |
work_dir |
| 672 |
.run_jj(["config", "set", "--repo", "revsets.log", "all()"]) |
| 673 |
.success(); |
| 674 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 675 |
@ 1a0f8336974a y2 parents: y1 |
| 676 |
○ 0e07ea90229f y1 parents: y |
| 677 |
◆ a0fb97fc193f y parents: |
| 678 |
│ ○ d6c30fecfe88 x3 parents: x2 |
| 679 |
│ ○ 6411b5818334 x2 parents: x1 |
| 680 |
│ ○ 6d01ab1fb731 x1 parents: x |
| 681 |
│ ◆ 8ceb28e1dc31 x parents: |
| 682 |
├─╯ |
| 683 |
◆ 000000000000 parents: |
| 684 |
[EOF] |
| 685 |
"); |
| 686 |
|
| 687 |
work_dir |
| 688 |
.run_jj(["parallelize", "subject(x*)", "subject(y*)"]) |
| 689 |
.success(); |
| 690 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 691 |
@ 264da1b87cf3 y2 parents: |
| 692 |
│ ○ 636008757721 y1 parents: |
| 693 |
├─╯ |
| 694 |
│ ○ db5717c9c093 x3 parents: |
| 695 |
├─╯ |
| 696 |
│ ○ 3e5fc34764e8 x2 parents: |
| 697 |
├─╯ |
| 698 |
│ ○ 71aeaa5e8891 x1 parents: |
| 699 |
├─╯ |
| 700 |
│ ◆ a0fb97fc193f y parents: |
| 701 |
├─╯ |
| 702 |
│ ◆ 8ceb28e1dc31 x parents: |
| 703 |
├─╯ |
| 704 |
◆ 000000000000 parents: |
| 705 |
[EOF] |
| 706 |
"); |
| 707 |
} |
| 708 |
|
| 709 |
#[test] |
| 710 |
fn test_parallelize_no_immutable_non_base_commits() { |
| 711 |
let test_env = TestEnvironment::default(); |
| 712 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 713 |
let work_dir = test_env.work_dir("repo"); |
| 714 |
|
| 715 |
work_dir.run_jj(["new", "root()", "-m=x"]).success(); |
| 716 |
work_dir.run_jj(["new", "-m=x1"]).success(); |
| 717 |
work_dir.run_jj(["new", "-m=x2"]).success(); |
| 718 |
work_dir.run_jj(["new", "-m=x3"]).success(); |
| 719 |
|
| 720 |
work_dir |
| 721 |
.run_jj([ |
| 722 |
"config", |
| 723 |
"set", |
| 724 |
"--repo", |
| 725 |
"revset-aliases.'immutable_heads()'", |
| 726 |
"subject(x1)", |
| 727 |
]) |
| 728 |
.success(); |
| 729 |
work_dir |
| 730 |
.run_jj(["config", "set", "--repo", "revsets.log", "all()"]) |
| 731 |
.success(); |
| 732 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 733 |
@ d6c30fecfe88 x3 parents: x2 |
| 734 |
○ 6411b5818334 x2 parents: x1 |
| 735 |
◆ 6d01ab1fb731 x1 parents: x |
| 736 |
◆ 8ceb28e1dc31 x parents: |
| 737 |
◆ 000000000000 parents: |
| 738 |
[EOF] |
| 739 |
"); |
| 740 |
|
| 741 |
let output = work_dir.run_jj(["parallelize", "subject(x*)"]); |
| 742 |
insta::assert_snapshot!(output, @r#" |
| 743 |
------- stderr ------- |
| 744 |
Error: Commit 6d01ab1fb731 is immutable |
| 745 |
Hint: Could not modify commit: kkmpptxz 6d01ab1f (empty) x1 |
| 746 |
Hint: Immutable commits are used to protect shared history. |
| 747 |
Hint: For more information, see: |
| 748 |
- https://docs.jj-vcs.dev/latest/config/#set-of-immutable-commits |
| 749 |
- `jj help -k config`, "Set of immutable commits" |
| 750 |
Hint: This operation would rewrite 1 immutable commits. |
| 751 |
[EOF] |
| 752 |
[exit status: 1] |
| 753 |
"#); |
| 754 |
} |
| 755 |
|
| 756 |
#[must_use] |
| 757 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 758 |
let template = r#" |
| 759 |
separate(" ", |
| 760 |
commit_id.short(), |
| 761 |
description.first_line(), |
| 762 |
"parents:", |
| 763 |
parents.map(|c|c.description().first_line()) |
| 764 |
)"#; |
| 765 |
work_dir.run_jj(["log", "-T", template]) |
| 766 |
} |