just playing with tangled
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::Path;
16
17use crate::common::TestEnvironment;
18
19#[test]
20fn test_parallelize_no_descendants() {
21 let test_env = TestEnvironment::default();
22 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
23 let workspace_path = test_env.env_root().join("repo");
24
25 for n in 1..6 {
26 test_env.jj_cmd_ok(&workspace_path, &["commit", &format!("-m{n}")]);
27 }
28 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=6"]);
29 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
30 @ b911505e443e 6 parents: 5
31 ◉ 2e00cb15c7b6 5 parents: 4
32 ◉ 9df3c87db1a2 4 parents: 3
33 ◉ 9f5b59fa4622 3 parents: 2
34 ◉ d826910d21fb 2 parents: 1
35 ◉ dc0e5d6135ce 1 parents:
36 ◉ 000000000000 parents:
37 "###);
38
39 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "description(1)::"]);
40 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
41 @ 6c7b60a45eb6 6 parents:
42 │ ◉ 296f48966777 5 parents:
43 ├─╯
44 │ ◉ 524062469789 4 parents:
45 ├─╯
46 │ ◉ a9334ecaa379 3 parents:
47 ├─╯
48 │ ◉ 3a7b37ebe843 2 parents:
49 ├─╯
50 │ ◉ dc0e5d6135ce 1 parents:
51 ├─╯
52 ◉ 000000000000 parents:
53 "###);
54}
55
56// Only the head commit has descendants.
57#[test]
58fn test_parallelize_with_descendants_simple() {
59 let test_env = TestEnvironment::default();
60 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
61 let workspace_path = test_env.env_root().join("repo");
62
63 for n in 1..6 {
64 test_env.jj_cmd_ok(&workspace_path, &["commit", &format!("-m{n}")]);
65 }
66 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=6"]);
67 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
68 @ b911505e443e 6 parents: 5
69 ◉ 2e00cb15c7b6 5 parents: 4
70 ◉ 9df3c87db1a2 4 parents: 3
71 ◉ 9f5b59fa4622 3 parents: 2
72 ◉ d826910d21fb 2 parents: 1
73 ◉ dc0e5d6135ce 1 parents:
74 ◉ 000000000000 parents:
75 "###);
76
77 test_env.jj_cmd_ok(
78 &workspace_path,
79 &["parallelize", "description(1)::description(4)"],
80 );
81 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
82 @ 259d624373d7 6 parents: 5
83 ◉ 60d419591c77 5 parents: 1 2 3 4
84 ├─┬─┬─╮
85 │ │ │ ◉ 524062469789 4 parents:
86 │ │ ◉ │ a9334ecaa379 3 parents:
87 │ │ ├─╯
88 │ ◉ │ 3a7b37ebe843 2 parents:
89 │ ├─╯
90 ◉ │ dc0e5d6135ce 1 parents:
91 ├─╯
92 ◉ 000000000000 parents:
93 "###);
94}
95
96// One of the commits being parallelized has a child that isn't being
97// parallelized. That child will become a merge of any ancestors which are being
98// parallelized.
99#[test]
100fn test_parallelize_where_interior_has_non_target_children() {
101 let test_env = TestEnvironment::default();
102 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
103 let workspace_path = test_env.env_root().join("repo");
104
105 for n in 1..6 {
106 test_env.jj_cmd_ok(&workspace_path, &["commit", &format!("-m{n}")]);
107 }
108 test_env.jj_cmd_ok(&workspace_path, &["new", "description(2)", "-m=2c"]);
109 test_env.jj_cmd_ok(&workspace_path, &["new", "description(5)", "-m=6"]);
110 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
111 @ d27ee705f7a9 6 parents: 5
112 ◉ 2e00cb15c7b6 5 parents: 4
113 ◉ 9df3c87db1a2 4 parents: 3
114 ◉ 9f5b59fa4622 3 parents: 2
115 │ ◉ 9c8865930f3c 2c parents: 2
116 ├─╯
117 ◉ d826910d21fb 2 parents: 1
118 ◉ dc0e5d6135ce 1 parents:
119 ◉ 000000000000 parents:
120 "###);
121
122 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "dc0::9df"]);
123 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
124 @ a42de3959cae 6 parents: 5
125 ◉ d907c901bad0 5 parents: 1 2 3 4
126 ├─┬─┬─╮
127 │ │ │ ◉ b8f977c12383 4 parents:
128 │ │ ◉ │ 7be8374575b9 3 parents:
129 │ │ ├─╯
130 │ │ │ ◉ 2a4c3dab2a50 2c parents: 1 2
131 ╭─┬───╯
132 │ ◉ │ 96ce11389312 2 parents:
133 │ ├─╯
134 ◉ │ dc0e5d6135ce 1 parents:
135 ├─╯
136 ◉ 000000000000 parents:
137 "###);
138}
139
140#[test]
141fn test_parallelize_where_root_has_non_target_children() {
142 let test_env = TestEnvironment::default();
143 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
144 let workspace_path = test_env.env_root().join("repo");
145
146 for n in 1..4 {
147 test_env.jj_cmd_ok(&workspace_path, &["commit", &format!("-m{n}")]);
148 }
149 test_env.jj_cmd_ok(&workspace_path, &["new", "description(1)", "-m=1c"]);
150 test_env.jj_cmd_ok(&workspace_path, &["new", "description(3)", "-m=4"]);
151 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
152 @ 7636b3f489f4 4 parents: 3
153 ◉ 9f5b59fa4622 3 parents: 2
154 ◉ d826910d21fb 2 parents: 1
155 │ ◉ 50e2ced81124 1c parents: 1
156 ├─╯
157 ◉ dc0e5d6135ce 1 parents:
158 ◉ 000000000000 parents:
159 "###);
160 test_env.jj_cmd_ok(
161 &workspace_path,
162 &["parallelize", "description(1)::description(3)"],
163 );
164 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
165 @ d024344469c3 4 parents: 1 2 3
166 ├─┬─╮
167 │ │ ◉ 5bd049136a7c 3 parents:
168 │ ◉ │ 60f737a5a4a7 2 parents:
169 │ ├─╯
170 │ │ ◉ 50e2ced81124 1c parents: 1
171 ├───╯
172 ◉ │ dc0e5d6135ce 1 parents:
173 ├─╯
174 ◉ 000000000000 parents:
175 "###);
176}
177
178// One of the commits being parallelized has a child that is a merge commit.
179#[test]
180fn test_parallelize_with_merge_commit_child() {
181 let test_env = TestEnvironment::default();
182 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
183 let workspace_path = test_env.env_root().join("repo");
184
185 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m", "1"]);
186 for n in 2..4 {
187 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m", &n.to_string()]);
188 }
189 test_env.jj_cmd_ok(&workspace_path, &["new", "root()", "-m", "a"]);
190 test_env.jj_cmd_ok(
191 &workspace_path,
192 &["new", "description(2)", "description(a)", "-m", "2a-c"],
193 );
194 test_env.jj_cmd_ok(&workspace_path, &["new", "description(3)", "-m", "4"]);
195 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
196 @ 90a65779e2ec 4 parents: 3
197 ◉ 9f5b59fa4622 3 parents: 2
198 │ ◉ a01c1fad8506 2a-c parents: 2 a
199 ╭─┤
200 │ ◉ 1eb902150bb9 a parents:
201 ◉ │ d826910d21fb 2 parents: 1
202 ◉ │ dc0e5d6135ce 1 parents:
203 ├─╯
204 ◉ 000000000000 parents:
205 "###);
206
207 // After this finishes, child-2a will have three parents: "1", "2", and "a".
208 test_env.jj_cmd_ok(
209 &workspace_path,
210 &["parallelize", "description(1)::description(3)"],
211 );
212 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
213 @ 6107429ab54b 4 parents: 1 2 3
214 ├─┬─╮
215 │ │ ◉ a9334ecaa379 3 parents:
216 │ │ │ ◉ a386386b94bc 2a-c parents: 1 2 a
217 ╭─┬───┤
218 │ │ │ ◉ 1eb902150bb9 a parents:
219 │ │ ├─╯
220 │ ◉ │ 3a7b37ebe843 2 parents:
221 │ ├─╯
222 ◉ │ dc0e5d6135ce 1 parents:
223 ├─╯
224 ◉ 000000000000 parents:
225 "###);
226}
227
228#[test]
229fn test_parallelize_disconnected_target_commits() {
230 let test_env = TestEnvironment::default();
231 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
232 let workspace_path = test_env.env_root().join("repo");
233
234 for n in 1..3 {
235 test_env.jj_cmd_ok(&workspace_path, &["commit", &format!("-m{n}")]);
236 }
237 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=3"]);
238 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
239 @ 9f5b59fa4622 3 parents: 2
240 ◉ d826910d21fb 2 parents: 1
241 ◉ dc0e5d6135ce 1 parents:
242 ◉ 000000000000 parents:
243 "###);
244
245 let (stdout, stderr) = test_env.jj_cmd_ok(
246 &workspace_path,
247 &["parallelize", "description(1)", "description(3)"],
248 );
249 insta::assert_snapshot!(stdout, @"");
250 insta::assert_snapshot!(stderr, @r###"
251 Nothing changed.
252 "###);
253 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
254 @ 9f5b59fa4622 3 parents: 2
255 ◉ d826910d21fb 2 parents: 1
256 ◉ dc0e5d6135ce 1 parents:
257 ◉ 000000000000 parents:
258 "###);
259}
260
261#[test]
262fn test_parallelize_head_is_a_merge() {
263 let test_env = TestEnvironment::default();
264 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
265 let workspace_path = test_env.env_root().join("repo");
266 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=0"]);
267 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=1"]);
268 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=2"]);
269 test_env.jj_cmd_ok(&workspace_path, &["new", "root()"]);
270 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=a"]);
271 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=b"]);
272 test_env.jj_cmd_ok(
273 &workspace_path,
274 &["new", "description(2)", "description(b)", "-m=merged-head"],
275 );
276 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
277 @ f2087b66e475 merged-head parents: 2 b
278 ├─╮
279 │ ◉ 5164ab888473 b parents: a
280 │ ◉ f16fe8ac5ce9 a parents:
281 ◉ │ fe79412860e8 2 parents: 1
282 ◉ │ a915696cf0ad 1 parents: 0
283 ◉ │ a56846756248 0 parents:
284 ├─╯
285 ◉ 000000000000 parents:
286 "###);
287
288 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "description(1)::"]);
289 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
290 @ babb4191912d merged-head parents: 0 b
291 ├─╮
292 │ ◉ 5164ab888473 b parents: a
293 │ ◉ f16fe8ac5ce9 a parents:
294 │ │ ◉ 36b2f866a798 2 parents: 0
295 ├───╯
296 │ │ ◉ a915696cf0ad 1 parents: 0
297 ├───╯
298 ◉ │ a56846756248 0 parents:
299 ├─╯
300 ◉ 000000000000 parents:
301 "###);
302}
303
304#[test]
305fn test_parallelize_interior_target_is_a_merge() {
306 let test_env = TestEnvironment::default();
307 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
308 let workspace_path = test_env.env_root().join("repo");
309 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=0"]);
310 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=1"]);
311 test_env.jj_cmd_ok(&workspace_path, &["new", "root()", "-m=a"]);
312 test_env.jj_cmd_ok(
313 &workspace_path,
314 &["new", "description(1)", "description(a)", "-m=2"],
315 );
316 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=3"]);
317 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
318 @ a6321093e3d3 3 parents: 2
319 ◉ 705c32f67ce1 2 parents: 1 a
320 ├─╮
321 │ ◉ 427890ea3f2b a parents:
322 ◉ │ a915696cf0ad 1 parents: 0
323 ◉ │ a56846756248 0 parents:
324 ├─╯
325 ◉ 000000000000 parents:
326 "###);
327
328 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "description(1)::"]);
329 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
330 @ cd0ac6ad1415 3 parents: 0 a
331 ├─╮
332 │ │ ◉ 1c240e875670 2 parents: 0 a
333 ╭─┬─╯
334 │ ◉ 427890ea3f2b a parents:
335 │ │ ◉ a915696cf0ad 1 parents: 0
336 ├───╯
337 ◉ │ a56846756248 0 parents:
338 ├─╯
339 ◉ 000000000000 parents:
340 "###);
341}
342
343#[test]
344fn test_parallelize_root_is_a_merge() {
345 let test_env = TestEnvironment::default();
346 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
347 let workspace_path = test_env.env_root().join("repo");
348 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=y"]);
349 test_env.jj_cmd_ok(&workspace_path, &["new", "root()", "-m=x"]);
350 test_env.jj_cmd_ok(
351 &workspace_path,
352 &["new", "description(y)", "description(x)", "-m=1"],
353 );
354 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=2"]);
355 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=3"]);
356 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
357 @ 9f66b50aa1f2 3 parents: 2
358 ◉ dd995ce87f21 2 parents: 1
359 ◉ 4b4941342e06 1 parents: y x
360 ├─╮
361 │ ◉ 4035b23c8f72 x parents:
362 ◉ │ f3ec359cf9ff y parents:
363 ├─╯
364 ◉ 000000000000 parents:
365 "###);
366
367 test_env.jj_cmd_ok(
368 &workspace_path,
369 &["parallelize", "description(1)::description(2)"],
370 );
371 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
372 @ d6df04b236b0 3 parents: 1 2
373 ├─╮
374 │ ◉ 38945baf55f4 2 parents: y x
375 │ ├─╮
376 ◉ │ │ 4b4941342e06 1 parents: y x
377 ╰─┬─╮
378 │ ◉ 4035b23c8f72 x parents:
379 ◉ │ f3ec359cf9ff y parents:
380 ├─╯
381 ◉ 000000000000 parents:
382 "###);
383}
384
385#[test]
386fn test_parallelize_multiple_heads() {
387 let test_env = TestEnvironment::default();
388 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
389 let workspace_path = test_env.env_root().join("repo");
390 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=0"]);
391 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=1"]);
392 test_env.jj_cmd_ok(&workspace_path, &["new", "description(0)", "-m=2"]);
393 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
394 @ 8314addde180 2 parents: 0
395 │ ◉ a915696cf0ad 1 parents: 0
396 ├─╯
397 ◉ a56846756248 0 parents:
398 ◉ 000000000000 parents:
399 "###);
400
401 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "description(0)::"]);
402 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
403 @ e84481c26195 2 parents:
404 │ ◉ 2047527ade93 1 parents:
405 ├─╯
406 │ ◉ a56846756248 0 parents:
407 ├─╯
408 ◉ 000000000000 parents:
409 "###);
410}
411
412// All heads must have the same children as the other heads, but only if they
413// have children. In this test only one head has children, so the command
414// succeeds.
415#[test]
416fn test_parallelize_multiple_heads_with_and_without_children() {
417 let test_env = TestEnvironment::default();
418 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
419 let workspace_path = test_env.env_root().join("repo");
420 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=0"]);
421 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=1"]);
422 test_env.jj_cmd_ok(&workspace_path, &["new", "description(0)", "-m=2"]);
423 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
424 @ 8314addde180 2 parents: 0
425 │ ◉ a915696cf0ad 1 parents: 0
426 ├─╯
427 ◉ a56846756248 0 parents:
428 ◉ 000000000000 parents:
429 "###);
430
431 test_env.jj_cmd_ok(
432 &workspace_path,
433 &["parallelize", "description(0)", "description(1)"],
434 );
435 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
436 ◉ 2047527ade93 1 parents:
437 │ @ 8314addde180 2 parents: 0
438 │ ◉ a56846756248 0 parents:
439 ├─╯
440 ◉ 000000000000 parents:
441 "###);
442}
443
444#[test]
445fn test_parallelize_multiple_roots() {
446 let test_env = TestEnvironment::default();
447 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
448 let workspace_path = test_env.env_root().join("repo");
449 test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=1"]);
450 test_env.jj_cmd_ok(&workspace_path, &["new", "root()", "-m=a"]);
451 test_env.jj_cmd_ok(
452 &workspace_path,
453 &["new", "description(1)", "description(a)", "-m=2"],
454 );
455 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=3"]);
456 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
457 @ 299099c22761 3 parents: 2
458 ◉ 0c4da981fc0a 2 parents: 1 a
459 ├─╮
460 │ ◉ 6d37472c632c a parents:
461 ◉ │ dc0e5d6135ce 1 parents:
462 ├─╯
463 ◉ 000000000000 parents:
464 "###);
465
466 // Succeeds because the roots have the same parents.
467 test_env.jj_cmd_ok(&workspace_path, &["parallelize", "root().."]);
468 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
469 @ 3c90598481cd 3 parents:
470 │ ◉ b96aa55582e5 2 parents:
471 ├─╯
472 │ ◉ 6d37472c632c a parents:
473 ├─╯
474 │ ◉ dc0e5d6135ce 1 parents:
475 ├─╯
476 ◉ 000000000000 parents:
477 "###);
478}
479
480#[test]
481fn test_parallelize_multiple_heads_with_different_children() {
482 let test_env = TestEnvironment::default();
483 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
484 let workspace_path = test_env.env_root().join("repo");
485 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=1"]);
486 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=2"]);
487 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=3"]);
488 test_env.jj_cmd_ok(&workspace_path, &["new", "root()"]);
489 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=a"]);
490 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=b"]);
491 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=c"]);
492 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
493 @ 9b5fa4b364d4 parents: c
494 ◉ 7b095ae9b21f c parents: b
495 ◉ 5164ab888473 b parents: a
496 ◉ f16fe8ac5ce9 a parents:
497 │ ◉ 9f5b59fa4622 3 parents: 2
498 │ ◉ d826910d21fb 2 parents: 1
499 │ ◉ dc0e5d6135ce 1 parents:
500 ├─╯
501 ◉ 000000000000 parents:
502 "###);
503
504 test_env.jj_cmd_ok(
505 &workspace_path,
506 &[
507 "parallelize",
508 "description(1)::description(2)",
509 "description(a)::description(b)",
510 ],
511 );
512 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
513 @ 582c6bd1e1fd parents: c
514 ◉ dd2db8b60a69 c parents: a b
515 ├─╮
516 │ ◉ 190b857f6cdd b parents:
517 ◉ │ f16fe8ac5ce9 a parents:
518 ├─╯
519 │ ◉ bbc313370f45 3 parents: 1 2
520 │ ├─╮
521 │ │ ◉ 96ce11389312 2 parents:
522 ├───╯
523 │ ◉ dc0e5d6135ce 1 parents:
524 ├─╯
525 ◉ 000000000000 parents:
526 "###);
527}
528
529#[test]
530fn test_parallelize_multiple_roots_with_different_parents() {
531 let test_env = TestEnvironment::default();
532 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
533 let workspace_path = test_env.env_root().join("repo");
534 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=1"]);
535 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=2"]);
536 test_env.jj_cmd_ok(&workspace_path, &["new", "root()"]);
537 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=a"]);
538 test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=b"]);
539 test_env.jj_cmd_ok(
540 &workspace_path,
541 &["new", "description(2)", "description(b)", "-m=merged-head"],
542 );
543 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
544 @ 1a8db14a8cf0 merged-head parents: 2 b
545 ├─╮
546 │ ◉ 401e43e9461f b parents: a
547 │ ◉ 66ea2ab19a70 a parents:
548 ◉ │ d826910d21fb 2 parents: 1
549 ◉ │ dc0e5d6135ce 1 parents:
550 ├─╯
551 ◉ 000000000000 parents:
552 "###);
553
554 test_env.jj_cmd_ok(
555 &workspace_path,
556 &["parallelize", "description(2)::", "description(b)::"],
557 );
558 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
559 @ 4224f9c9e598 merged-head parents: 1 a
560 ├─╮
561 │ │ ◉ 401e43e9461f b parents: a
562 │ ├─╯
563 │ ◉ 66ea2ab19a70 a parents:
564 │ │ ◉ d826910d21fb 2 parents: 1
565 ├───╯
566 ◉ │ dc0e5d6135ce 1 parents:
567 ├─╯
568 ◉ 000000000000 parents:
569 "###);
570}
571
572#[test]
573fn test_parallelize_complex_nonlinear_target() {
574 let test_env = TestEnvironment::default();
575 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
576 let workspace_path = test_env.env_root().join("repo");
577 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=0", "root()"]);
578 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=1", "description(0)"]);
579 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=2", "description(0)"]);
580 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=3", "description(0)"]);
581 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=4", "all:heads(..)"]);
582 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=1c", "description(1)"]);
583 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=2c", "description(2)"]);
584 test_env.jj_cmd_ok(&workspace_path, &["new", "-m=3c", "description(3)"]);
585 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
586 @ b043eb81416c 3c parents: 3
587 │ ◉ 48277ee9afe0 4 parents: 3 2 1
588 ╭─┼─╮
589 ◉ │ │ 944922f0c69f 3 parents: 0
590 │ │ │ ◉ 9d28e8e38435 2c parents: 2
591 │ ├───╯
592 │ ◉ │ 97d7522f40e8 2 parents: 0
593 ├─╯ │
594 │ ◉ │ 6c82c22a5e35 1c parents: 1
595 │ ├─╯
596 │ ◉ 0c058af014a6 1 parents: 0
597 ├─╯
598 ◉ 745bea8029c1 0 parents:
599 ◉ 000000000000 parents:
600 "###);
601
602 let (_stdout, stderr) = test_env.jj_cmd_ok(
603 &workspace_path,
604 &["parallelize", "description(0)::description(4)"],
605 );
606 insta::assert_snapshot!(stderr, @r###"
607 Working copy now at: yostqsxw 59a216e5 (empty) 3c
608 Parent commit : rlvkpnrz 745bea80 (empty) 0
609 Parent commit : mzvwutvl cb944786 (empty) 3
610 "###);
611 insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
612 @ 59a216e537c4 3c parents: 0 3
613 ├─╮
614 │ ◉ cb9447869bf0 3 parents:
615 │ │ ◉ 248ce1ffd76b 2c parents: 0 2
616 ╭───┤
617 │ │ ◉ 8f4b8ef68676 2 parents:
618 │ ├─╯
619 │ │ ◉ 55c626d090e2 1c parents: 0 1
620 ╭───┤
621 │ │ ◉ 82918d78c984 1 parents:
622 │ ├─╯
623 ◉ │ 745bea8029c1 0 parents:
624 ├─╯
625 │ ◉ 14ca4df576b3 4 parents:
626 ├─╯
627 ◉ 000000000000 parents:
628 "###)
629}
630
631fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
632 let template = r#"
633 separate(" ",
634 commit_id.short(),
635 description.first_line(),
636 "parents:",
637 parents.map(|c|c.description().first_line())
638 )"#;
639 test_env.jj_cmd_success(cwd, &["log", "-T", template])
640}