Debian Codegraph @

cli/tests/test_squash_command.rs

raw
1 // Copyright 2022 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 std::path::PathBuf;
16
17 use testutils::TestResult;
18
19 use crate::common::CommandOutput;
20 use crate::common::TestEnvironment;
21 use crate::common::TestWorkDir;
22
23 #[test]
24 fn test_squash() {
25 let test_env = TestEnvironment::default();
26 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
27 let work_dir = test_env.work_dir("repo");
28
29 work_dir
30 .run_jj(["bookmark", "create", "-r@", "a"])
31 .success();
32 work_dir.write_file("file1", "a\n");
33 work_dir.run_jj(["new"]).success();
34 work_dir
35 .run_jj(["bookmark", "create", "-r@", "b"])
36 .success();
37 work_dir.write_file("file1", "b\n");
38 work_dir.run_jj(["new"]).success();
39 work_dir
40 .run_jj(["bookmark", "create", "-r@", "c"])
41 .success();
42 work_dir.write_file("file1", "c\n");
43 // Test the setup
44 insta::assert_snapshot!(get_log_output(&work_dir), @"
45 @ 22be6c4e01da c
46 ○ 75591b1896b4 b
47 ○ e6086990958c a
48 ◆ 000000000000 (empty)
49 [EOF]
50 ");
51 let setup_opid = work_dir.current_operation_id();
52
53 // Squashes the working copy into the parent by default
54 let output = work_dir.run_jj(["squash"]);
55 insta::assert_snapshot!(output, @"
56 ------- stderr -------
57 Working copy (@) now at: vruxwmqv 2cf02eb8 (empty) (no description set)
58 Parent commit (@-) : kkmpptxz 9422c8d6 b c | (no description set)
59 [EOF]
60 ");
61 insta::assert_snapshot!(get_log_output(&work_dir), @"
62 @ 2cf02eb82d82 (empty)
63 ○ 9422c8d6f294 b c
64 ○ e6086990958c a
65 ◆ 000000000000 (empty)
66 [EOF]
67 ");
68 let output = work_dir.run_jj(["file", "show", "file1"]);
69 insta::assert_snapshot!(output, @"
70 c
71 [EOF]
72 ");
73
74 // Can squash a given commit into its parent
75 work_dir.run_jj(["op", "restore", &setup_opid]).success();
76 let output = work_dir.run_jj(["squash", "-r", "b"]);
77 insta::assert_snapshot!(output, @r"
78 ------- stderr -------
79 Rebased 1 descendant commits.
80 Working copy (@) now at: mzvwutvl 441a7a3a c | (no description set)
81 Parent commit (@-) : qpvuntsm 105931bf a b | (no description set)
82 [EOF]
83 ");
84 insta::assert_snapshot!(get_log_output(&work_dir), @"
85 @ 441a7a3a17b0 c
86 ○ 105931bfedad a b
87 ◆ 000000000000 (empty)
88 [EOF]
89 ");
90 let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
91 insta::assert_snapshot!(output, @"
92 b
93 [EOF]
94 ");
95 let output = work_dir.run_jj(["file", "show", "file1"]);
96 insta::assert_snapshot!(output, @"
97 c
98 [EOF]
99 ");
100
101 // Cannot squash a merge commit (because it's unclear which parent it should go
102 // into)
103 work_dir.run_jj(["op", "restore", &setup_opid]).success();
104 work_dir.run_jj(["edit", "b"]).success();
105 work_dir.run_jj(["new"]).success();
106 work_dir
107 .run_jj(["bookmark", "create", "-r@", "d"])
108 .success();
109 work_dir.write_file("file2", "d\n");
110 work_dir.run_jj(["new", "c", "d"]).success();
111 work_dir
112 .run_jj(["bookmark", "create", "-r@", "e"])
113 .success();
114 insta::assert_snapshot!(get_log_output(&work_dir), @"
115 @ e05d4caaf6ce e (empty)
116 ├─╮
117 │ ○ 9bb7863cfc78 d
118 ○ │ 22be6c4e01da c
119 ├─╯
120 ○ 75591b1896b4 b
121 ○ e6086990958c a
122 ◆ 000000000000 (empty)
123 [EOF]
124 ");
125 let output = work_dir.run_jj(["squash"]);
126 insta::assert_snapshot!(output, @"
127 ------- stderr -------
128 Error: Cannot squash merge commits without a specified destination
129 Hint: Use `--into` to specify which parent to squash into
130 [EOF]
131 [exit status: 1]
132 ");
133
134 // Can squash into a merge commit
135 work_dir.run_jj(["new", "e"]).success();
136 work_dir.write_file("file1", "e\n");
137 let output = work_dir.run_jj(["squash"]);
138 insta::assert_snapshot!(output, @"
139 ------- stderr -------
140 Working copy (@) now at: xlzxqlsl 91a81249 (empty) (no description set)
141 Parent commit (@-) : nmzmmopx 9155baf5 e | (no description set)
142 [EOF]
143 ");
144 insta::assert_snapshot!(get_log_output(&work_dir), @"
145 @ 91a81249954f (empty)
146 ○ 9155baf5ced1 e
147 ├─╮
148 │ ○ 9bb7863cfc78 d
149 ○ │ 22be6c4e01da c
150 ├─╯
151 ○ 75591b1896b4 b
152 ○ e6086990958c a
153 ◆ 000000000000 (empty)
154 [EOF]
155 ");
156 let output = work_dir.run_jj(["file", "show", "file1", "-r", "e"]);
157 insta::assert_snapshot!(output, @"
158 e
159 [EOF]
160 ");
161 }
162
163 #[test]
164 fn test_squash_partial() -> TestResult {
165 let mut test_env = TestEnvironment::default();
166 let edit_script = test_env.set_up_fake_diff_editor();
167 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
168 let work_dir = test_env.work_dir("repo");
169
170 work_dir
171 .run_jj(["bookmark", "create", "-r@", "a"])
172 .success();
173 work_dir.write_file("file1", "a\n");
174 work_dir.write_file("file2", "a\n");
175 work_dir.run_jj(["new"]).success();
176 work_dir
177 .run_jj(["bookmark", "create", "-r@", "b"])
178 .success();
179 work_dir.write_file("file1", "b\n");
180 work_dir.write_file("file2", "b\n");
181 work_dir.run_jj(["new"]).success();
182 work_dir
183 .run_jj(["bookmark", "create", "-r@", "c"])
184 .success();
185 work_dir.write_file("file1", "c\n");
186 work_dir.write_file("file2", "c\n");
187 // Test the setup
188 insta::assert_snapshot!(get_log_output(&work_dir), @"
189 @ 87059ac9657b c
190 ○ f2c9709f39e9 b
191 ○ 64ea60be8d77 a
192 ◆ 000000000000 (empty)
193 [EOF]
194 ");
195
196 let start_op_id = work_dir.current_operation_id();
197
198 // If we don't make any changes in the diff-editor, the whole change is moved
199 // into the parent
200 std::fs::write(&edit_script, "dump JJ-INSTRUCTIONS instrs")?;
201 let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
202 insta::assert_snapshot!(output, @r"
203 ------- stderr -------
204 Rebased 1 descendant commits.
205 Working copy (@) now at: mzvwutvl 34484d82 c | (no description set)
206 Parent commit (@-) : qpvuntsm 3141e675 a b | (no description set)
207 [EOF]
208 ");
209
210 let instrs = std::fs::read_to_string(test_env.env_root().join("instrs"))?;
211 insta::assert_snapshot!(
212 instrs, @"
213 You are moving changes from: kkmpptxz f2c9709f b | (no description set)
214 into commit: qpvuntsm 64ea60be a | (no description set)
215
216 The left side of the diff shows the contents of the parent commit. The
217 right side initially shows the contents of the commit you're moving
218 changes from.
219
220 Adjust the right side until the diff shows the changes you want to move
221 to the destination. If you don't make any changes, then all the changes
222 from the source will be moved into the destination.
223 ");
224
225 insta::assert_snapshot!(get_log_output(&work_dir), @"
226 @ 34484d825f47 c
227 ○ 3141e67514f6 a b
228 ◆ 000000000000 (empty)
229 [EOF]
230 ");
231 let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
232 insta::assert_snapshot!(output, @"
233 b
234 [EOF]
235 ");
236
237 // Can squash only some changes in interactive mode
238 work_dir.run_jj(["op", "restore", &start_op_id]).success();
239 std::fs::write(&edit_script, "reset file1")?;
240 let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
241 insta::assert_snapshot!(output, @r"
242 ------- stderr -------
243 Rebased 2 descendant commits.
244 Working copy (@) now at: mzvwutvl 37e1a0ef c | (no description set)
245 Parent commit (@-) : kkmpptxz b41e789d b | (no description set)
246 [EOF]
247 ");
248 insta::assert_snapshot!(get_log_output(&work_dir), @"
249 @ 37e1a0ef57ff c
250 ○ b41e789df71c b
251 ○ 3af17565155e a
252 ◆ 000000000000 (empty)
253 [EOF]
254 ");
255 let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
256 insta::assert_snapshot!(output, @"
257 a
258 [EOF]
259 ");
260 let output = work_dir.run_jj(["file", "show", "file2", "-r", "a"]);
261 insta::assert_snapshot!(output, @"
262 b
263 [EOF]
264 ");
265 let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
266 insta::assert_snapshot!(output, @"
267 b
268 [EOF]
269 ");
270 let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
271 insta::assert_snapshot!(output, @"
272 b
273 [EOF]
274 ");
275
276 // Can squash only some changes in non-interactive mode
277 work_dir.run_jj(["op", "restore", &start_op_id]).success();
278 // Clear the script so we know it won't be used even without -i
279 std::fs::write(&edit_script, "")?;
280 let output = work_dir.run_jj(["squash", "-r", "b", "file2"]);
281 insta::assert_snapshot!(output, @r"
282 ------- stderr -------
283 Rebased 2 descendant commits.
284 Working copy (@) now at: mzvwutvl 72ff256c c | (no description set)
285 Parent commit (@-) : kkmpptxz dd056a92 b | (no description set)
286 [EOF]
287 ");
288 insta::assert_snapshot!(get_log_output(&work_dir), @"
289 @ 72ff256cd290 c
290 ○ dd056a925eb3 b
291 ○ cf083f1d9ccf a
292 ◆ 000000000000 (empty)
293 [EOF]
294 ");
295 let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
296 insta::assert_snapshot!(output, @"
297 a
298 [EOF]
299 ");
300 let output = work_dir.run_jj(["file", "show", "file2", "-r", "a"]);
301 insta::assert_snapshot!(output, @"
302 b
303 [EOF]
304 ");
305 let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
306 insta::assert_snapshot!(output, @"
307 b
308 [EOF]
309 ");
310 let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
311 insta::assert_snapshot!(output, @"
312 b
313 [EOF]
314 ");
315
316 // If we specify only a non-existent file, then nothing changes.
317 work_dir.run_jj(["op", "restore", &start_op_id]).success();
318 let output = work_dir.run_jj(["squash", "-r", "b", "nonexistent"]);
319 insta::assert_snapshot!(output, @"
320 ------- stderr -------
321 Warning: No matching entries for paths: nonexistent
322 Nothing changed.
323 [EOF]
324 ");
325
326 // We get a warning if we pass a positional argument that looks like a revset
327 work_dir.run_jj(["op", "restore", &start_op_id]).success();
328 let output = work_dir.run_jj(["squash", "b"]);
329 insta::assert_snapshot!(output, @r#"
330 ------- stderr -------
331 Warning: No matching entries for paths: b
332 Warning: The argument "b" is being interpreted as a fileset expression. To specify a revset, pass -r "b" instead.
333 Nothing changed.
334 [EOF]
335 "#);
336
337 // No warning if we pass a positional argument does not parse as a revset
338 work_dir.run_jj(["op", "restore", &start_op_id]).success();
339 let output = work_dir.run_jj(["squash", ".tmp"]);
340 insta::assert_snapshot!(output, @"
341 ------- stderr -------
342 Warning: No matching entries for paths: .tmp
343 Nothing changed.
344 [EOF]
345 ");
346
347 // we can use --interactive and fileset together
348 work_dir.run_jj(["op", "restore", &start_op_id]).success();
349 work_dir.write_file("file3", "foo\n");
350 std::fs::write(&edit_script, "reset file1")?;
351 let output = work_dir.run_jj(["squash", "-i", "file1", "file3"]);
352 insta::assert_snapshot!(output, @r"
353 ------- stderr -------
354 Rebased 1 descendant commits.
355 Working copy (@) now at: mzvwutvl 3615d80e c | (no description set)
356 Parent commit (@-) : kkmpptxz 037106c4 b | (no description set)
357 [EOF]
358 ");
359 let output = work_dir.run_jj(["log", "-s"]);
360 insta::assert_snapshot!(output, @"
361 @ mzvwutvl [email protected] 2001-02-03 08:05:38 c 3615d80e
362 │ (no description set)
363 │ M file1
364 │ M file2
365 ○ kkmpptxz [email protected] 2001-02-03 08:05:38 b 037106c4
366 │ (no description set)
367 │ M file1
368 │ M file2
369 │ A file3
370 ○ qpvuntsm [email protected] 2001-02-03 08:05:09 a 64ea60be
371 │ (no description set)
372 │ A file1
373 │ A file2
374 ◆ zzzzzzzz root() 00000000
375 [EOF]
376 ");
377
378 // Error if no changes selected in interactive mode
379 work_dir.run_jj(["op", "restore", &start_op_id]).success();
380 std::fs::write(&edit_script, "reset file1\0reset file2")?;
381 let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
382 insta::assert_snapshot!(output, @"
383 ------- stderr -------
384 Error: No changes selected
385 [EOF]
386 [exit status: 1]
387 ");
388 insta::assert_snapshot!(get_log_output(&work_dir), @"
389 @ 87059ac9657b c
390 ○ f2c9709f39e9 b
391 ○ 64ea60be8d77 a
392 ◆ 000000000000 (empty)
393 [EOF]
394 ");
395 Ok(())
396 }
397
398 #[test]
399 fn test_squash_revision_flag_exactly_one_errors() {
400 // Test error cases where the `--revision` flag does not resolve to a single
401 // revision.
402
403 let test_env = TestEnvironment::default();
404 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
405 let work_dir = test_env.work_dir("repo");
406
407 work_dir.write_file("file1", "a\n");
408 work_dir.run_jj(["bookmark", "create", "a"]).success();
409 work_dir.run_jj(["new"]).success();
410 work_dir.write_file("file1", "b\n");
411 work_dir.run_jj(["bookmark", "create", "b"]).success();
412 work_dir.run_jj(["new"]).success();
413 work_dir.write_file("file1", "c\n");
414 work_dir.run_jj(["bookmark", "create", "c"]).success();
415
416 insta::assert_snapshot!(get_log_output(&work_dir), @"
417 @ 68a8af64312c c
418 ○ ffe91d7f157b b
419 ○ eb7b8a1f02b8 a
420 ◆ 000000000000 (empty)
421 [EOF]
422 ");
423
424 // Try to squash multiple revisions.
425 let output = work_dir.run_jj(["squash", "-rb|c"]);
426 insta::assert_snapshot!(output, @"
427 ------- stderr -------
428 Error: Revset `b|c` resolved to more than one revision
429 Hint: The revset `b|c` resolved to these revisions:
430 mzvwutvl 68a8af64 c | (no description set)
431 kkmpptxz ffe91d7f b | (no description set)
432 Hint: --revision must resolve to a single revision. Use --from and --into instead if you want to squash multiple revisions.
433 [EOF]
434 [exit status: 1]
435 ");
436
437 // Try to squash no revisions.
438 let output = work_dir.run_jj(["squash", "-rb&c"]);
439 insta::assert_snapshot!(output, @"
440 ------- stderr -------
441 Error: Revset `b&c` didn't resolve to any revisions
442 [EOF]
443 [exit status: 1]
444 ");
445 }
446
447 #[test]
448 fn test_squash_keep_emptied() {
449 let test_env = TestEnvironment::default();
450 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
451 let work_dir = test_env.work_dir("repo");
452
453 work_dir
454 .run_jj(["bookmark", "create", "-r@", "a"])
455 .success();
456 work_dir.write_file("file1", "a\n");
457 work_dir.run_jj(["new"]).success();
458 work_dir
459 .run_jj(["bookmark", "create", "-r@", "b"])
460 .success();
461 work_dir.write_file("file1", "b\n");
462 work_dir.run_jj(["new"]).success();
463 work_dir
464 .run_jj(["bookmark", "create", "-r@", "c"])
465 .success();
466 work_dir.write_file("file1", "c\n");
467 // Test the setup
468
469 insta::assert_snapshot!(get_log_output(&work_dir), @"
470 @ 22be6c4e01da c
471 ○ 75591b1896b4 b
472 ○ e6086990958c a
473 ◆ 000000000000 (empty)
474 [EOF]
475 ");
476
477 let output = work_dir.run_jj(["squash", "-r", "b", "--keep-emptied"]);
478 insta::assert_snapshot!(output, @r"
479 ------- stderr -------
480 Rebased 2 descendant commits.
481 Working copy (@) now at: mzvwutvl 093590e0 c | (no description set)
482 Parent commit (@-) : kkmpptxz 357946cf b | (empty) (no description set)
483 [EOF]
484 ");
485 // With --keep-emptied, b remains even though it is now empty.
486 insta::assert_snapshot!(get_log_output(&work_dir), @"
487 @ 093590e044bd c
488 ○ 357946cf85df b (empty)
489 ○ 2269fb3b12f5 a
490 ◆ 000000000000 (empty)
491 [EOF]
492 ");
493 let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
494 insta::assert_snapshot!(output, @"
495 b
496 [EOF]
497 ");
498 }
499
500 #[test]
501 fn test_squash_from_to() {
502 let test_env = TestEnvironment::default();
503 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
504 let work_dir = test_env.work_dir("repo");
505
506 // Create history like this:
507 // F
508 // |
509 // E C
510 // | |
511 // D B
512 // |/
513 // A
514 //
515 // When moving changes between e.g. C and F, we should not get unrelated changes
516 // from B and D.
517 work_dir
518 .run_jj(["bookmark", "create", "-r@", "a"])
519 .success();
520 work_dir.write_file("file1", "a\n");
521 work_dir.write_file("file2", "a\n");
522 work_dir.write_file("file3", "a\n");
523 work_dir.run_jj(["new"]).success();
524 work_dir
525 .run_jj(["bookmark", "create", "-r@", "b"])
526 .success();
527 work_dir.write_file("file3", "b\n");
528 work_dir.run_jj(["new"]).success();
529 work_dir
530 .run_jj(["bookmark", "create", "-r@", "c"])
531 .success();
532 work_dir.write_file("file1", "c\n");
533 work_dir.run_jj(["edit", "a"]).success();
534 work_dir.run_jj(["new"]).success();
535 work_dir
536 .run_jj(["bookmark", "create", "-r@", "d"])
537 .success();
538 work_dir.write_file("file3", "d\n");
539 work_dir.run_jj(["new"]).success();
540 work_dir
541 .run_jj(["bookmark", "create", "-r@", "e"])
542 .success();
543 work_dir.write_file("file2", "e\n");
544 work_dir.run_jj(["new"]).success();
545 work_dir
546 .run_jj(["bookmark", "create", "-r@", "f"])
547 .success();
548 work_dir.write_file("file2", "f\n");
549 // Test the setup
550 insta::assert_snapshot!(get_log_output(&work_dir), @"
551 @ 0fac1124d1ad f
552 ○ 4ebe104a0e4e e
553 ○ dc71a460d5d6 d
554 │ ○ ee0b260ffc44 c
555 │ ○ e31bf988d7c9 b
556 ├─╯
557 ○ e3e04beaf7d3 a
558 ◆ 000000000000 (empty)
559 [EOF]
560 ");
561 let setup_opid = work_dir.current_operation_id();
562
563 // No-op if source and destination are the same
564 let output = work_dir.run_jj(["squash", "--into", "@"]);
565 insta::assert_snapshot!(output, @"
566 ------- stderr -------
567 Nothing changed.
568 [EOF]
569 ");
570
571 // Can squash from sibling, which results in the source being abandoned
572 let output = work_dir.run_jj(["squash", "--from", "c"]);
573 insta::assert_snapshot!(output, @"
574 ------- stderr -------
575 Working copy (@) now at: kmkuslsw 941ab024 f | (no description set)
576 Parent commit (@-) : znkkpsqq 4ebe104a e | (no description set)
577 Added 0 files, modified 1 files, removed 0 files
578 [EOF]
579 ");
580 insta::assert_snapshot!(get_log_output(&work_dir), @"
581 @ 941ab024b3f8 f
582 ○ 4ebe104a0e4e e
583 ○ dc71a460d5d6 d
584 │ ○ e31bf988d7c9 b c
585 ├─╯
586 ○ e3e04beaf7d3 a
587 ◆ 000000000000 (empty)
588 [EOF]
589 ");
590 // The change from the source has been applied
591 let output = work_dir.run_jj(["file", "show", "file1"]);
592 insta::assert_snapshot!(output, @"
593 c
594 [EOF]
595 ");
596 // File `file2`, which was not changed in source, is unchanged
597 let output = work_dir.run_jj(["file", "show", "file2"]);
598 insta::assert_snapshot!(output, @"
599 f
600 [EOF]
601 ");
602
603 // Can squash from ancestor
604 work_dir.run_jj(["op", "restore", &setup_opid]).success();
605 let output = work_dir.run_jj(["squash", "--from", "@--"]);
606 insta::assert_snapshot!(output, @"
607 ------- stderr -------
608 Working copy (@) now at: kmkuslsw c102d2c4 f | (no description set)
609 Parent commit (@-) : znkkpsqq beb7c033 e | (no description set)
610 [EOF]
611 ");
612 // The change has been removed from the source (the change pointed to by 'd'
613 // became empty and was abandoned)
614 insta::assert_snapshot!(get_log_output(&work_dir), @"
615 @ c102d2c4e165 f
616 ○ beb7c0338f7c e
617 │ ○ ee0b260ffc44 c
618 │ ○ e31bf988d7c9 b
619 ├─╯
620 ○ e3e04beaf7d3 a d
621 ◆ 000000000000 (empty)
622 [EOF]
623 ");
624 // The change from the source has been applied (the file contents were already
625 // "f", as is typically the case when moving changes from an ancestor)
626 let output = work_dir.run_jj(["file", "show", "file2"]);
627 insta::assert_snapshot!(output, @"
628 f
629 [EOF]
630 ");
631
632 // Can squash from descendant
633 work_dir.run_jj(["op", "restore", &setup_opid]).success();
634 let output = work_dir.run_jj(["squash", "--from", "e", "--into", "d"]);
635 insta::assert_snapshot!(output, @r"
636 ------- stderr -------
637 Rebased 1 descendant commits.
638 Working copy (@) now at: kmkuslsw 1bc21d4e f | (no description set)
639 Parent commit (@-) : vruxwmqv 8b6b080a d e | (no description set)
640 [EOF]
641 ");
642 // The change has been removed from the source (the change pointed to by 'e'
643 // became empty and was abandoned)
644 insta::assert_snapshot!(get_log_output(&work_dir), @"
645 @ 1bc21d4e92d6 f
646 ○ 8b6b080ab587 d e
647 │ ○ ee0b260ffc44 c
648 │ ○ e31bf988d7c9 b
649 ├─╯
650 ○ e3e04beaf7d3 a
651 ◆ 000000000000 (empty)
652 [EOF]
653 ");
654 // The change from the source has been applied
655 let output = work_dir.run_jj(["file", "show", "file2", "-r", "d"]);
656 insta::assert_snapshot!(output, @"
657 e
658 [EOF]
659 ");
660
661 // Can squash into the sources
662 work_dir.run_jj(["op", "restore", &setup_opid]).success();
663 let output = work_dir.run_jj(["squash", "--from", "e::f", "--into", "d"]);
664 insta::assert_snapshot!(output, @"
665 ------- stderr -------
666 Working copy (@) now at: pkstwlsy 76baa567 (empty) (no description set)
667 Parent commit (@-) : vruxwmqv 415e4069 d e f | (no description set)
668 [EOF]
669 ");
670 // The change has been removed from the source (the change pointed to by 'e'
671 // became empty and was abandoned)
672 insta::assert_snapshot!(get_log_output(&work_dir), @"
673 @ 76baa567ed0a (empty)
674 ○ 415e40694e88 d e f
675 │ ○ ee0b260ffc44 c
676 │ ○ e31bf988d7c9 b
677 ├─╯
678 ○ e3e04beaf7d3 a
679 ◆ 000000000000 (empty)
680 [EOF]
681 ");
682 // The change from the source has been applied
683 let output = work_dir.run_jj(["file", "show", "file2", "-r", "d"]);
684 insta::assert_snapshot!(output, @"
685 f
686 [EOF]
687 ");
688 }
689
690 #[test]
691 fn test_squash_from_to_partial() -> TestResult {
692 let mut test_env = TestEnvironment::default();
693 let edit_script = test_env.set_up_fake_diff_editor();
694 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
695 let work_dir = test_env.work_dir("repo");
696
697 // Create history like this:
698 // C
699 // |
700 // D B
701 // |/
702 // A
703 work_dir
704 .run_jj(["bookmark", "create", "-r@", "a"])
705 .success();
706 work_dir.write_file("file1", "a\n");
707 work_dir.write_file("file2", "a\n");
708 work_dir.write_file("file3", "a\n");
709 work_dir.run_jj(["new"]).success();
710 work_dir
711 .run_jj(["bookmark", "create", "-r@", "b"])
712 .success();
713 work_dir.write_file("file3", "b\n");
714 work_dir.run_jj(["new"]).success();
715 work_dir
716 .run_jj(["bookmark", "create", "-r@", "c"])
717 .success();
718 work_dir.write_file("file1", "c\n");
719 work_dir.write_file("file2", "c\n");
720 work_dir.run_jj(["edit", "a"]).success();
721 work_dir.run_jj(["new"]).success();
722 work_dir
723 .run_jj(["bookmark", "create", "-r@", "d"])
724 .success();
725 work_dir.write_file("file3", "d\n");
726 // Test the setup
727 insta::assert_snapshot!(get_log_output(&work_dir), @"
728 @ dc71a460d5d6 d
729 │ ○ 499d601f6046 c
730 │ ○ e31bf988d7c9 b
731 ├─╯
732 ○ e3e04beaf7d3 a
733 ◆ 000000000000 (empty)
734 [EOF]
735 ");
736 let setup_opid = work_dir.current_operation_id();
737
738 // If we don't make any changes in the diff-editor, the whole change is moved
739 let output = work_dir.run_jj(["squash", "-i", "--from", "c"]);
740 insta::assert_snapshot!(output, @"
741 ------- stderr -------
742 Working copy (@) now at: vruxwmqv 85589465 d | (no description set)
743 Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
744 Added 0 files, modified 2 files, removed 0 files
745 [EOF]
746 ");
747 insta::assert_snapshot!(get_log_output(&work_dir), @"
748 @ 85589465a5f7 d
749 │ ○ e31bf988d7c9 b c
750 ├─╯
751 ○ e3e04beaf7d3 a
752 ◆ 000000000000 (empty)
753 [EOF]
754 ");
755 // The changes from the source has been applied
756 let output = work_dir.run_jj(["file", "show", "file1"]);
757 insta::assert_snapshot!(output, @"
758 c
759 [EOF]
760 ");
761 let output = work_dir.run_jj(["file", "show", "file2"]);
762 insta::assert_snapshot!(output, @"
763 c
764 [EOF]
765 ");
766 // File `file3`, which was not changed in source, is unchanged
767 let output = work_dir.run_jj(["file", "show", "file3"]);
768 insta::assert_snapshot!(output, @"
769 d
770 [EOF]
771 ");
772
773 // Can squash only part of the change in interactive mode
774 work_dir.run_jj(["op", "restore", &setup_opid]).success();
775 std::fs::write(&edit_script, "reset file2")?;
776 let output = work_dir.run_jj(["squash", "-i", "--from", "c"]);
777 insta::assert_snapshot!(output, @"
778 ------- stderr -------
779 Working copy (@) now at: vruxwmqv 62bd5cd9 d | (no description set)
780 Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
781 Added 0 files, modified 1 files, removed 0 files
782 [EOF]
783 ");
784 insta::assert_snapshot!(get_log_output(&work_dir), @"
785 @ 62bd5cd9f413 d
786 │ ○ 2748f30463ed c
787 │ ○ e31bf988d7c9 b
788 ├─╯
789 ○ e3e04beaf7d3 a
790 ◆ 000000000000 (empty)
791 [EOF]
792 ");
793 // The selected change from the source has been applied
794 let output = work_dir.run_jj(["file", "show", "file1"]);
795 insta::assert_snapshot!(output, @"
796 c
797 [EOF]
798 ");
799 // The unselected change from the source has not been applied
800 let output = work_dir.run_jj(["file", "show", "file2"]);
801 insta::assert_snapshot!(output, @"
802 a
803 [EOF]
804 ");
805 // File `file3`, which was changed in source's parent, is unchanged
806 let output = work_dir.run_jj(["file", "show", "file3"]);
807 insta::assert_snapshot!(output, @"
808 d
809 [EOF]
810 ");
811
812 // Can squash only part of the change from a sibling in non-interactive mode
813 work_dir.run_jj(["op", "restore", &setup_opid]).success();
814 // Clear the script so we know it won't be used
815 std::fs::write(&edit_script, "")?;
816 let output = work_dir.run_jj(["squash", "--from", "c", "file1"]);
817 insta::assert_snapshot!(output, @"
818 ------- stderr -------
819 Working copy (@) now at: vruxwmqv 76bf6139 d | (no description set)
820 Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
821 Added 0 files, modified 1 files, removed 0 files
822 [EOF]
823 ");
824 insta::assert_snapshot!(get_log_output(&work_dir), @"
825 @ 76bf613928cf d
826 │ ○ 9d4418d4828e c
827 │ ○ e31bf988d7c9 b
828 ├─╯
829 ○ e3e04beaf7d3 a
830 ◆ 000000000000 (empty)
831 [EOF]
832 ");
833 // The selected change from the source has been applied
834 let output = work_dir.run_jj(["file", "show", "file1"]);
835 insta::assert_snapshot!(output, @"
836 c
837 [EOF]
838 ");
839 // The unselected change from the source has not been applied
840 let output = work_dir.run_jj(["file", "show", "file2"]);
841 insta::assert_snapshot!(output, @"
842 a
843 [EOF]
844 ");
845 // File `file3`, which was changed in source's parent, is unchanged
846 let output = work_dir.run_jj(["file", "show", "file3"]);
847 insta::assert_snapshot!(output, @"
848 d
849 [EOF]
850 ");
851
852 // Can squash only part of the change from a descendant in non-interactive mode
853 work_dir.run_jj(["op", "restore", &setup_opid]).success();
854 // Clear the script so we know it won't be used
855 std::fs::write(&edit_script, "")?;
856 let output = work_dir.run_jj(["squash", "--from", "c", "--into", "b", "file1"]);
857 insta::assert_snapshot!(output, @r"
858 ------- stderr -------
859 Rebased 1 descendant commits.
860 [EOF]
861 ");
862 insta::assert_snapshot!(get_log_output(&work_dir), @"
863 @ dc71a460d5d6 d
864 │ ○ f964ce4bca71 c
865 │ ○ e12c895adba6 b
866 ├─╯
867 ○ e3e04beaf7d3 a
868 ◆ 000000000000 (empty)
869 [EOF]
870 ");
871 // The selected change from the source has been applied
872 let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
873 insta::assert_snapshot!(output, @"
874 c
875 [EOF]
876 ");
877 // The unselected change from the source has not been applied
878 let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
879 insta::assert_snapshot!(output, @"
880 a
881 [EOF]
882 ");
883
884 // If we specify only a non-existent file, then nothing changes.
885 work_dir.run_jj(["op", "restore", &setup_opid]).success();
886 let output = work_dir.run_jj(["squash", "--from", "c", "nonexistent"]);
887 insta::assert_snapshot!(output, @"
888 ------- stderr -------
889 Warning: No matching entries for paths: nonexistent
890 Nothing changed.
891 [EOF]
892 ");
893 Ok(())
894 }
895
896 #[test]
897 fn test_squash_from_multiple() {
898 let test_env = TestEnvironment::default();
899 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
900 let work_dir = test_env.work_dir("repo");
901
902 // Create history like this:
903 // F
904 // |
905 // E
906 // /|\
907 // B C D
908 // \|/
909 // A
910 work_dir
911 .run_jj(["bookmark", "create", "-r@", "a"])
912 .success();
913 work_dir.write_file("file", "a\n");
914 work_dir.run_jj(["new"]).success();
915 work_dir
916 .run_jj(["bookmark", "create", "-r@", "b"])
917 .success();
918 work_dir.write_file("file", "b\n");
919 work_dir.run_jj(["new", "@-"]).success();
920 work_dir
921 .run_jj(["bookmark", "create", "-r@", "c"])
922 .success();
923 work_dir.write_file("file", "c\n");
924 work_dir.run_jj(["new", "@-"]).success();
925 work_dir
926 .run_jj(["bookmark", "create", "-r@", "d"])
927 .success();
928 work_dir.write_file("file", "d\n");
929 work_dir.run_jj(["new", "visible_heads()"]).success();
930 work_dir
931 .run_jj(["bookmark", "create", "-r@", "e"])
932 .success();
933 work_dir.write_file("file", "e\n");
934 work_dir.run_jj(["new"]).success();
935 work_dir
936 .run_jj(["bookmark", "create", "-r@", "f"])
937 .success();
938 work_dir.write_file("file", "f\n");
939 // Test the setup
940 insta::assert_snapshot!(get_log_output(&work_dir), @"
941 @ 65e53f39b4d6 f
942 ○ 7dc592781647 e
943 ├─┬─╮
944 │ │ ○ fed4d1a2e491 b
945 │ ○ │ d7e94ec7e73e c
946 │ ├─╯
947 ○ │ 8acbb71558d5 d
948 ├─╯
949 ○ e88768e65e67 a
950 ◆ 000000000000 (empty)
951 [EOF]
952 ");
953 let setup_opid = work_dir.current_operation_id();
954
955 // Squash a few commits sideways
956 let output = work_dir.run_jj(["squash", "--from=b", "--from=c", "--into=d"]);
957 insta::assert_snapshot!(output, @r"
958 ------- stderr -------
959 Rebased 2 descendant commits.
960 Working copy (@) now at: kpqxywon f584da5f f | (no description set)
961 Parent commit (@-) : yostqsxw 6fbe5593 e | (no description set)
962 New conflicts appeared in 1 commits:
963 yqosqzyt 3592e886 d | (conflict) (no description set)
964 Hint: To resolve the conflicts, start by creating a commit on top of
965 the conflicted commit:
966 jj new yqosqzyt
967 Then use `jj resolve`, or edit the conflict markers in the file directly.
968 Once the conflicts are resolved, you can inspect the result with `jj diff`.
969 Then run `jj squash` to move the resolution into the conflicted commit.
970 [EOF]
971 ");
972 insta::assert_snapshot!(get_log_output(&work_dir), @"
973 @ f584da5f6b0d f
974 ○ 6fbe5593f24a e
975 ├─╮
976 × │ 3592e886b254 d
977 ├─╯
978 ○ e88768e65e67 a b c
979 ◆ 000000000000 (empty)
980 [EOF]
981 ");
982 // The changes from the sources have been applied
983 let output = work_dir.run_jj(["file", "show", "-r=d", "file"]);
984 insta::assert_snapshot!(output, @r"
985 <<<<<<< conflict 1 of 1
986 %%%%%%% diff from: qpvuntsm e88768e6 (parents of squashed revision)
987 \\\\\\\ to: yqosqzyt 8acbb715 (squash destination)
988 -a
989 +d
990 %%%%%%% diff from: qpvuntsm e88768e6 (parents of squashed revision)
991 \\\\\\\ to: kkmpptxz fed4d1a2 (squashed revision)
992 -a
993 +b
994 +++++++ mzvwutvl d7e94ec7 (squashed revision)
995 c
996 >>>>>>> conflict 1 of 1 ends
997 [EOF]
998 ");
999
1000 // Squash a few commits up an down
1001 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1002 let output = work_dir.run_jj(["squash", "--from=b|c|f", "--into=e"]);
1003 insta::assert_snapshot!(output, @r"
1004 ------- stderr -------
1005 Rebased 1 descendant commits.
1006 Working copy (@) now at: xznxytkn ec32238b (empty) (no description set)
1007 Parent commit (@-) : yostqsxw 5298eef6 e f | (no description set)
1008 [EOF]
1009 ");
1010 insta::assert_snapshot!(get_log_output(&work_dir), @"
1011 @ ec32238b2be5 (empty)
1012 ○ 5298eef6bca5 e f
1013 ├─╮
1014 ○ │ 8acbb71558d5 d
1015 ├─╯
1016 ○ e88768e65e67 a b c
1017 ◆ 000000000000 (empty)
1018 [EOF]
1019 ");
1020 // The changes from the sources have been applied to the destination
1021 let output = work_dir.run_jj(["file", "show", "-r=e", "file"]);
1022 insta::assert_snapshot!(output, @"
1023 f
1024 [EOF]
1025 ");
1026
1027 // Empty squash shouldn't crash
1028 let output = work_dir.run_jj(["squash", "--from=none()"]);
1029 insta::assert_snapshot!(output, @"
1030 ------- stderr -------
1031 Nothing changed.
1032 [EOF]
1033 ");
1034 }
1035
1036 #[test]
1037 fn test_squash_from_multiple_partial() {
1038 let test_env = TestEnvironment::default();
1039 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1040 let work_dir = test_env.work_dir("repo");
1041
1042 // Create history like this:
1043 // F
1044 // |
1045 // E
1046 // /|\
1047 // B C D
1048 // \|/
1049 // A
1050 work_dir
1051 .run_jj(["bookmark", "create", "-r@", "a"])
1052 .success();
1053 work_dir.write_file("file1", "a\n");
1054 work_dir.write_file("file2", "a\n");
1055 work_dir.run_jj(["new"]).success();
1056 work_dir
1057 .run_jj(["bookmark", "create", "-r@", "b"])
1058 .success();
1059 work_dir.write_file("file1", "b\n");
1060 work_dir.write_file("file2", "b\n");
1061 work_dir.run_jj(["new", "@-"]).success();
1062 work_dir
1063 .run_jj(["bookmark", "create", "-r@", "c"])
1064 .success();
1065 work_dir.write_file("file1", "c\n");
1066 work_dir.write_file("file2", "c\n");
1067 work_dir.run_jj(["new", "@-"]).success();
1068 work_dir
1069 .run_jj(["bookmark", "create", "-r@", "d"])
1070 .success();
1071 work_dir.write_file("file1", "d\n");
1072 work_dir.write_file("file2", "d\n");
1073 work_dir.run_jj(["new", "visible_heads()"]).success();
1074 work_dir
1075 .run_jj(["bookmark", "create", "-r@", "e"])
1076 .success();
1077 work_dir.write_file("file1", "e\n");
1078 work_dir.write_file("file2", "e\n");
1079 work_dir.run_jj(["new"]).success();
1080 work_dir
1081 .run_jj(["bookmark", "create", "-r@", "f"])
1082 .success();
1083 work_dir.write_file("file1", "f\n");
1084 work_dir.write_file("file2", "f\n");
1085 // Test the setup
1086 insta::assert_snapshot!(get_log_output(&work_dir), @"
1087 @ 4558bd852475 f
1088 ○ e2db96b2e57a e
1089 ├─┬─╮
1090 │ │ ○ f2c9709f39e9 b
1091 │ ○ │ aa908686a197 c
1092 │ ├─╯
1093 ○ │ f6812ff8db35 d
1094 ├─╯
1095 ○ 64ea60be8d77 a
1096 ◆ 000000000000 (empty)
1097 [EOF]
1098 ");
1099 let setup_opid = work_dir.current_operation_id();
1100
1101 // Partially squash a few commits sideways
1102 let output = work_dir.run_jj(["squash", "--from=b|c", "--into=d", "file1"]);
1103 insta::assert_snapshot!(output, @r"
1104 ------- stderr -------
1105 Rebased 2 descendant commits.
1106 Working copy (@) now at: kpqxywon 9113246b f | (no description set)
1107 Parent commit (@-) : yostqsxw f069c595 e | (no description set)
1108 New conflicts appeared in 1 commits:
1109 yqosqzyt 35455ce2 d | (conflict) (no description set)
1110 Hint: To resolve the conflicts, start by creating a commit on top of
1111 the conflicted commit:
1112 jj new yqosqzyt
1113 Then use `jj resolve`, or edit the conflict markers in the file directly.
1114 Once the conflicts are resolved, you can inspect the result with `jj diff`.
1115 Then run `jj squash` to move the resolution into the conflicted commit.
1116 [EOF]
1117 ");
1118 insta::assert_snapshot!(get_log_output(&work_dir), @"
1119 @ 9113246bdbc0 f
1120 ○ f069c5953603 e
1121 ├─┬─╮
1122 │ │ ○ e9db15b956c4 b
1123 │ ○ │ 83cbe51db94d c
1124 │ ├─╯
1125 × │ 35455ce2c7a8 d
1126 ├─╯
1127 ○ 64ea60be8d77 a
1128 ◆ 000000000000 (empty)
1129 [EOF]
1130 ");
1131 // The selected changes have been removed from the sources
1132 let output = work_dir.run_jj(["file", "show", "-r=b", "file1"]);
1133 insta::assert_snapshot!(output, @"
1134 a
1135 [EOF]
1136 ");
1137 let output = work_dir.run_jj(["file", "show", "-r=c", "file1"]);
1138 insta::assert_snapshot!(output, @"
1139 a
1140 [EOF]
1141 ");
1142 // The selected changes from the sources have been applied
1143 let output = work_dir.run_jj(["file", "show", "-r=d", "file1"]);
1144 insta::assert_snapshot!(output, @r"
1145 <<<<<<< conflict 1 of 1
1146 %%%%%%% diff from: qpvuntsm 64ea60be (parents of squashed revision)
1147 \\\\\\\ to: yqosqzyt f6812ff8 (squash destination)
1148 -a
1149 +d
1150 %%%%%%% diff from: qpvuntsm 64ea60be (parents of squashed revision)
1151 \\\\\\\ to: selected changes for squash (from kkmpptxz f2c9709f)
1152 -a
1153 +b
1154 +++++++ selected changes for squash (from mzvwutvl aa908686)
1155 c
1156 >>>>>>> conflict 1 of 1 ends
1157 [EOF]
1158 ");
1159 // The unselected change from the sources have not been applied to the
1160 // destination
1161 let output = work_dir.run_jj(["file", "show", "-r=d", "file2"]);
1162 insta::assert_snapshot!(output, @"
1163 d
1164 [EOF]
1165 ");
1166
1167 // Partially squash a few commits up an down
1168 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1169 let output = work_dir.run_jj(["squash", "--from=b|c|f", "--into=e", "file1"]);
1170 insta::assert_snapshot!(output, @r"
1171 ------- stderr -------
1172 Rebased 1 descendant commits.
1173 Working copy (@) now at: kpqxywon b5a40c15 f | (no description set)
1174 Parent commit (@-) : yostqsxw 5dea187c e | (no description set)
1175 [EOF]
1176 ");
1177 insta::assert_snapshot!(get_log_output(&work_dir), @"
1178 @ b5a40c154611 f
1179 ○ 5dea187c414d e
1180 ├─┬─╮
1181 │ │ ○ 8b9afc05ca07 b
1182 │ ○ │ 5630471a8fd5 c
1183 │ ├─╯
1184 ○ │ f6812ff8db35 d
1185 ├─╯
1186 ○ 64ea60be8d77 a
1187 ◆ 000000000000 (empty)
1188 [EOF]
1189 ");
1190 // The selected changes have been removed from the sources
1191 let output = work_dir.run_jj(["file", "show", "-r=b", "file1"]);
1192 insta::assert_snapshot!(output, @"
1193 a
1194 [EOF]
1195 ");
1196 let output = work_dir.run_jj(["file", "show", "-r=c", "file1"]);
1197 insta::assert_snapshot!(output, @"
1198 a
1199 [EOF]
1200 ");
1201 let output = work_dir.run_jj(["file", "show", "-r=f", "file1"]);
1202 insta::assert_snapshot!(output, @"
1203 f
1204 [EOF]
1205 ");
1206 // The selected changes from the sources have been applied to the destination
1207 let output = work_dir.run_jj(["file", "show", "-r=e", "file1"]);
1208 insta::assert_snapshot!(output, @"
1209 f
1210 [EOF]
1211 ");
1212 // The unselected changes from the sources have not been applied
1213 let output = work_dir.run_jj(["file", "show", "-r=d", "file2"]);
1214 insta::assert_snapshot!(output, @"
1215 d
1216 [EOF]
1217 ");
1218 }
1219
1220 #[test]
1221 fn test_squash_from_multiple_partial_no_op() {
1222 let test_env = TestEnvironment::default();
1223 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1224 let work_dir = test_env.work_dir("repo");
1225
1226 // Create history like this:
1227 // B C D
1228 // \|/
1229 // A
1230 work_dir.run_jj(["describe", "-m=a"]).success();
1231 work_dir.write_file("a", "a\n");
1232 work_dir.run_jj(["new", "-m=b"]).success();
1233 work_dir.write_file("b", "b\n");
1234 work_dir.run_jj(["new", "@-", "-m=c"]).success();
1235 work_dir.write_file("c", "c\n");
1236 work_dir.run_jj(["new", "@-", "-m=d"]).success();
1237 work_dir.write_file("d", "d\n");
1238 // Test the setup
1239 insta::assert_snapshot!(get_log_output(&work_dir), @"
1240 @ fdb92bc249a0 d
1241 │ ○ 0dc8cb72859d c
1242 ├─╯
1243 │ ○ b1a17f79a1a5 b
1244 ├─╯
1245 ○ 93d495c46d89 a
1246 ◆ 000000000000 (empty)
1247 [EOF]
1248 ");
1249 let setup_opid = work_dir.current_operation_id();
1250
1251 // Source commits that didn't match the paths are not rewritten
1252 let output = work_dir.run_jj(["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "b"]);
1253 insta::assert_snapshot!(output, @"
1254 ------- stderr -------
1255 Working copy (@) now at: mzvwutvl 6dfc239e d
1256 Parent commit (@-) : qpvuntsm 93d495c4 a
1257 Added 1 files, modified 0 files, removed 0 files
1258 [EOF]
1259 ");
1260 insta::assert_snapshot!(get_log_output(&work_dir), @"
1261 @ 6dfc239e2ba3 d
1262 │ ○ 0dc8cb72859d c
1263 ├─╯
1264 ○ 93d495c46d89 a
1265 ◆ 000000000000 (empty)
1266 [EOF]
1267 ");
1268 let output = work_dir.run_jj([
1269 "evolog",
1270 "-T",
1271 r#"separate(" ", commit.commit_id().short(), commit.description())"#,
1272 ]);
1273 insta::assert_snapshot!(output, @"
1274 @ 6dfc239e2ba3 d
1275 ├─╮
1276 │ ○ b1a17f79a1a5 b
1277 │ ○ d8b7d57239ca b
1278 ○ fdb92bc249a0 d
1279 ○ af709ccc1ca9 d
1280 [EOF]
1281 ");
1282
1283 // If no source commits match the paths, then the whole operation is a no-op
1284 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1285 let output = work_dir.run_jj(["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "a"]);
1286 insta::assert_snapshot!(output, @"
1287 ------- stderr -------
1288 Nothing changed.
1289 [EOF]
1290 ");
1291 insta::assert_snapshot!(get_log_output(&work_dir), @"
1292 @ fdb92bc249a0 d
1293 │ ○ 0dc8cb72859d c
1294 ├─╯
1295 │ ○ b1a17f79a1a5 b
1296 ├─╯
1297 ○ 93d495c46d89 a
1298 ◆ 000000000000 (empty)
1299 [EOF]
1300 ");
1301 }
1302
1303 #[must_use]
1304 fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
1305 let template = r#"separate(
1306 " ",
1307 commit_id.short(),
1308 bookmarks,
1309 description,
1310 if(empty, "(empty)")
1311 )"#;
1312 work_dir.run_jj(["log", "-T", template])
1313 }
1314
1315 #[test]
1316 fn test_squash_description() -> TestResult {
1317 let mut test_env = TestEnvironment::default();
1318 let edit_script = test_env.set_up_fake_editor();
1319 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1320 let work_dir = test_env.work_dir("repo");
1321
1322 std::fs::write(&edit_script, r#"fail"#)?;
1323
1324 // If both descriptions are empty, the resulting description is empty
1325 work_dir.write_file("file1", "a\n");
1326 work_dir.write_file("file2", "a\n");
1327 work_dir.run_jj(["new"]).success();
1328 work_dir.write_file("file1", "b\n");
1329 work_dir.write_file("file2", "b\n");
1330 work_dir.run_jj(["debug", "snapshot"]).success();
1331 let setup_opid1 = work_dir.current_operation_id();
1332 work_dir.run_jj(["squash"]).success();
1333 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
1334
1335 // If the destination's description is empty and the source's description is
1336 // non-empty, the resulting description is from the source
1337 work_dir.run_jj(["op", "restore", &setup_opid1]).success();
1338 work_dir.run_jj(["describe", "-m", "source"]).success();
1339 work_dir.run_jj(["squash"]).success();
1340 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1341 source
1342 [EOF]
1343 ");
1344
1345 // If the destination description is non-empty and the source's description is
1346 // empty, the resulting description is from the destination
1347 work_dir.run_jj(["op", "restore", &setup_opid1]).success();
1348 work_dir
1349 .run_jj(["describe", "@-", "-m", "destination"])
1350 .success();
1351 let setup_opid2 = work_dir.current_operation_id();
1352 work_dir.run_jj(["squash"]).success();
1353 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1354 destination
1355 [EOF]
1356 ");
1357
1358 // An explicit description on the command-line overrides this
1359 work_dir.run_jj(["op", "restore", &setup_opid2]).success();
1360 work_dir.run_jj(["squash", "-m", "custom"]).success();
1361 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1362 custom
1363 [EOF]
1364 ");
1365
1366 // If both descriptions were non-empty, we get asked for a combined description
1367 work_dir.run_jj(["op", "restore", &setup_opid2]).success();
1368 work_dir.run_jj(["describe", "-m", "source"]).success();
1369 let setup_opid3 = work_dir.current_operation_id();
1370 std::fs::write(&edit_script, "dump editor0")?;
1371 work_dir.run_jj(["squash"]).success();
1372 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1373 destination
1374
1375 source
1376 [EOF]
1377 ");
1378 let editor0 = std::fs::read_to_string(test_env.env_root().join("editor0"))?;
1379 insta::assert_snapshot!(
1380 editor0, @r#"
1381 JJ: Enter a description for the combined commit.
1382 JJ: Description from the destination commit:
1383 destination
1384
1385 JJ: Description from source commit:
1386 source
1387
1388 JJ: Change ID: qpvuntsm
1389 JJ: This commit contains the following changes:
1390 JJ: A file1
1391 JJ: A file2
1392 JJ:
1393 JJ: Lines starting with "JJ:" (like this one) will be removed.
1394 "#);
1395
1396 // An explicit description on the command-line overrides prevents launching an
1397 // editor
1398 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1399 work_dir.run_jj(["squash", "-m", "custom"]).success();
1400 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1401 custom
1402 [EOF]
1403 ");
1404
1405 // An explicit description on the command-line includes the trailers when
1406 // templates.commit_trailers is configured
1407 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1408 work_dir
1409 .run_jj([
1410 "squash",
1411 "--config",
1412 r#"templates.commit_trailers='"CC: " ++ committer.email()'"#,
1413 "-m",
1414 "custom",
1415 ])
1416 .success();
1417 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1418 custom
1419
1420 CC: [email protected]
1421 [EOF]
1422 ");
1423
1424 // If the source's *content* doesn't become empty, then the source remains and
1425 // both descriptions are unchanged
1426 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1427 work_dir.run_jj(["squash", "file1"]).success();
1428 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1429 destination
1430 [EOF]
1431 ");
1432 insta::assert_snapshot!(get_description(&work_dir, "@"), @"
1433 source
1434 [EOF]
1435 ");
1436
1437 // A combined description should only contain the trailers from the
1438 // commit_trailers template that were not in the squashed commits
1439 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1440 work_dir
1441 .run_jj(["describe", "-m", "source\n\nfoo: bar"])
1442 .success();
1443 std::fs::write(&edit_script, "dump editor0")?;
1444 work_dir
1445 .run_jj([
1446 "squash",
1447 "--config",
1448 r#"templates.commit_trailers='"CC: [email protected]\nfoo: bar"'"#,
1449 ])
1450 .success();
1451 let editor0 = std::fs::read_to_string(test_env.env_root().join("editor0"))?;
1452 insta::assert_snapshot!(
1453 editor0, @r#"
1454 JJ: Enter a description for the combined commit.
1455 JJ: Description from the destination commit:
1456 destination
1457
1458 JJ: Description from source commit:
1459 source
1460
1461 foo: bar
1462
1463 JJ: Trailers not found in the squashed commits:
1464 CC: [email protected]
1465
1466 JJ: Change ID: qpvuntsm
1467 JJ: This commit contains the following changes:
1468 JJ: A file1
1469 JJ: A file2
1470 JJ:
1471 JJ: Lines starting with "JJ:" (like this one) will be removed.
1472 "#);
1473
1474 // No complaints when commits have identical trailers, order irrelevant
1475 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1476 work_dir
1477 .run_jj(["describe", "-m", "source\n\nfoo: bar\nbaz: quux"])
1478 .success();
1479 std::fs::write(&edit_script, "dump editor0").unwrap();
1480 work_dir
1481 .run_jj([
1482 "squash",
1483 "--config",
1484 r#"templates.commit_trailers='"baz: quux\nfoo: bar"'"#,
1485 ])
1486 .success();
1487 insta::assert_snapshot!(
1488 std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#"
1489 JJ: Enter a description for the combined commit.
1490 JJ: Description from the destination commit:
1491 destination
1492
1493 JJ: Description from source commit:
1494 source
1495
1496 foo: bar
1497 baz: quux
1498
1499 JJ: Change ID: qpvuntsm
1500 JJ: This commit contains the following changes:
1501 JJ: A file1
1502 JJ: A file2
1503 JJ:
1504 JJ: Lines starting with "JJ:" (like this one) will be removed.
1505 "#);
1506
1507 // If the destination description is non-empty and the source's description is
1508 // empty, the resulting description is from the destination, with additional
1509 // trailers if defined in the commit_trailers template
1510 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1511 work_dir.run_jj(["describe", "-m", ""]).success();
1512 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1513 @ 452e4831d64b
1514 ○ e650dfcd7312 destination
1515 ◆ 000000000000
1516 [EOF]
1517 ");
1518 work_dir
1519 .run_jj([
1520 "squash",
1521 "--config",
1522 r#"templates.commit_trailers='"CC: [email protected]"'"#,
1523 ])
1524 .success();
1525 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1526 destination
1527
1528 CC: [email protected]
1529 [EOF]
1530 ");
1531
1532 // If a single description is non-empty, the resulting description is
1533 // from the destination, with additional trailers if defined in the
1534 // commit_trailers template
1535 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1536 work_dir
1537 .run_jj(["describe", "-r", "@-", "-m", ""])
1538 .success();
1539 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1540 @ 78e7f58582e8 source
1541 ○ a01e1865957e
1542 ◆ 000000000000
1543 [EOF]
1544 ");
1545 work_dir
1546 .run_jj([
1547 "squash",
1548 "--config",
1549 r#"templates.commit_trailers='"CC: [email protected]"'"#,
1550 ])
1551 .success();
1552 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1553 source
1554
1555 CC: [email protected]
1556 [EOF]
1557 ");
1558
1559 // squashing messages with empty descriptions shouldn't add any trailer
1560 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1561 work_dir
1562 .run_jj(["describe", "-r", "..", "-m", ""])
1563 .success();
1564 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1565 @ 8a34624ec18b
1566 ○ 2560c9e5ef72
1567 ◆ 000000000000
1568 [EOF]
1569 ");
1570 work_dir
1571 .run_jj([
1572 "squash",
1573 "--config",
1574 r#"templates.commit_trailers='"CC: [email protected]"'"#,
1575 ])
1576 .success();
1577 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
1578
1579 // squashing messages with --use-destination-message on a commit with an
1580 // empty description shouldn't add any trailer
1581 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1582 work_dir
1583 .run_jj(["describe", "-r", "@-", "-m", ""])
1584 .success();
1585 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1586 @ 405f52356ed5 source
1587 ○ ecf32ca3d742
1588 ◆ 000000000000
1589 [EOF]
1590 ");
1591 work_dir
1592 .run_jj([
1593 "squash",
1594 "--use-destination-message",
1595 "--config",
1596 r#"templates.commit_trailers='"CC: [email protected]"'"#,
1597 ])
1598 .success();
1599 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
1600
1601 // squashing with an empty message on the command line shouldn't add
1602 // any trailer
1603 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1604 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1605 @ 2a79b102bf46 source
1606 ○ e650dfcd7312 destination
1607 ◆ 000000000000
1608 [EOF]
1609 ");
1610 work_dir
1611 .run_jj([
1612 "squash",
1613 "--message",
1614 "",
1615 "--config",
1616 r#"templates.commit_trailers='"CC: [email protected]"'"#,
1617 ])
1618 .success();
1619 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
1620
1621 // Invalid trailer content
1622 work_dir.run_jj(["op", "restore", &setup_opid3]).success();
1623 work_dir.write_file("data.txt", b"\xff\n");
1624 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1625 @ 9eec7f21360c source
1626 ○ e650dfcd7312 destination
1627 ◆ 000000000000
1628 [EOF]
1629 ");
1630 let output = work_dir.run_jj([
1631 "squash",
1632 "--config",
1633 r#"templates.commit_trailers='indent("Content: ", diff.git())'"#,
1634 ]);
1635 insta::assert_snapshot!(output, @"
1636 ------- stderr -------
1637 Error: Trailers should be valid utf-8
1638 [EOF]
1639 [exit status: 1]
1640 ");
1641 Ok(())
1642 }
1643
1644 #[test]
1645 fn test_squash_description_editor_avoids_unc() -> TestResult {
1646 let mut test_env = TestEnvironment::default();
1647 let edit_script = test_env.set_up_fake_editor();
1648 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1649 let work_dir = test_env.work_dir("repo");
1650
1651 work_dir.write_file("file1", "a\n");
1652 work_dir.write_file("file2", "a\n");
1653 work_dir.run_jj(["new"]).success();
1654 work_dir.write_file("file1", "b\n");
1655 work_dir.write_file("file2", "b\n");
1656 work_dir
1657 .run_jj(["describe", "@-", "-m", "destination"])
1658 .success();
1659 work_dir.run_jj(["describe", "-m", "source"]).success();
1660
1661 std::fs::write(edit_script, "dump-path path")?;
1662 work_dir.run_jj(["squash"]).success();
1663
1664 let edited_path = PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path"))?);
1665 // While `assert!(!edited_path.starts_with("//?/"))` could work here in most
1666 // cases, it fails when it is not safe to strip the prefix, such as paths
1667 // over 260 chars.
1668 assert_eq!(edited_path, dunce::simplified(&edited_path));
1669 Ok(())
1670 }
1671
1672 #[test]
1673 fn test_squash_empty() {
1674 let mut test_env = TestEnvironment::default();
1675 test_env.set_up_fake_editor();
1676 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1677 let work_dir = test_env.work_dir("repo");
1678
1679 work_dir.run_jj(["commit", "-m", "parent"]).success();
1680
1681 let output = work_dir.run_jj(["squash"]);
1682 insta::assert_snapshot!(output, @"
1683 ------- stderr -------
1684 Working copy (@) now at: kkmpptxz db7ad962 (empty) (no description set)
1685 Parent commit (@-) : qpvuntsm 771da191 (empty) parent
1686 [EOF]
1687 ");
1688 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1689 parent
1690 [EOF]
1691 ");
1692
1693 work_dir.run_jj(["describe", "-m", "child"]).success();
1694 work_dir.run_jj(["squash"]).success();
1695 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
1696 parent
1697
1698 child
1699 [EOF]
1700 ");
1701 }
1702
1703 #[test]
1704 fn test_squash_use_destination_message() {
1705 let test_env = TestEnvironment::default();
1706 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1707 let work_dir = test_env.work_dir("repo");
1708
1709 work_dir.run_jj(["commit", "-m=a"]).success();
1710 work_dir.run_jj(["commit", "-m=b"]).success();
1711 work_dir.run_jj(["describe", "-m=c"]).success();
1712 // Test the setup
1713 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1714 @ cf388db088f7 c
1715 ○ e412ddda5587 b
1716 ○ b86e28cd6862 a
1717 ◆ 000000000000
1718 [EOF]
1719 ");
1720 let setup_opid = work_dir.current_operation_id();
1721
1722 // Squash the current revision using the short name for the option.
1723 work_dir.run_jj(["squash", "-u"]).success();
1724 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1725 @ 70c0f74e4486
1726 ○ 44c1701e4ef8 b
1727 ○ b86e28cd6862 a
1728 ◆ 000000000000
1729 [EOF]
1730 ");
1731
1732 // Undo and squash again, but this time squash both "b" and "c" into "a".
1733 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1734 work_dir
1735 .run_jj([
1736 "squash",
1737 "--use-destination-message",
1738 "--from=subject(b)::",
1739 "--into=subject(a)",
1740 ])
1741 .success();
1742 insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
1743 @ e5a16e0e6a46
1744 ○ 6e47254e0803 a
1745 ◆ 000000000000
1746 [EOF]
1747 ");
1748 }
1749
1750 #[test]
1751 fn test_squash_option_exclusion() {
1752 let test_env = TestEnvironment::default();
1753 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1754 let work_dir = test_env.work_dir("repo");
1755 work_dir.run_jj(["commit", "-m=a"]).success();
1756 work_dir.run_jj(["describe", "-m=b"]).success();
1757
1758 insta::assert_snapshot!(work_dir.run_jj([
1759 "squash",
1760 "--message=123",
1761 "--use-destination-message",
1762 ]), @"
1763 ------- stderr -------
1764 error: the argument '--message <MESSAGE>' cannot be used with '--use-destination-message'
1765
1766 Usage: jj squash --message <MESSAGE> [FILESETS]...
1767
1768 For more information, try '--help'.
1769 [EOF]
1770 [exit status: 2]
1771 ");
1772
1773 insta::assert_snapshot!(work_dir.run_jj([
1774 "squash",
1775 "-r@",
1776 "--into=@-"
1777 ]), @"
1778 ------- stderr -------
1779 error: the argument '--revision <REVSET>' cannot be used with '--into <REVSET>'
1780
1781 Usage: jj squash --revision <REVSET> [FILESETS]...
1782
1783 For more information, try '--help'.
1784 [EOF]
1785 [exit status: 2]
1786 ");
1787
1788 insta::assert_snapshot!(work_dir.run_jj([
1789 "squash",
1790 "-r@",
1791 "--onto=@-"
1792 ]), @"
1793 ------- stderr -------
1794 error: the argument '--revision <REVSET>' cannot be used with '--onto <REVSETS>'
1795
1796 Usage: jj squash --revision <REVSET> [FILESETS]...
1797
1798 For more information, try '--help'.
1799 [EOF]
1800 [exit status: 2]
1801 ");
1802
1803 insta::assert_snapshot!(work_dir.run_jj([
1804 "squash",
1805 "-r@",
1806 "--after=@-"
1807 ]), @"
1808 ------- stderr -------
1809 error: the argument '--revision <REVSET>' cannot be used with '--insert-after <REVSETS>'
1810
1811 Usage: jj squash --revision <REVSET> [FILESETS]...
1812
1813 For more information, try '--help'.
1814 [EOF]
1815 [exit status: 2]
1816 ");
1817
1818 insta::assert_snapshot!(work_dir.run_jj([
1819 "squash",
1820 "-r@",
1821 "--before=@-"
1822 ]), @"
1823 ------- stderr -------
1824 error: the argument '--revision <REVSET>' cannot be used with '--insert-before <REVSETS>'
1825
1826 Usage: jj squash --revision <REVSET> [FILESETS]...
1827
1828 For more information, try '--help'.
1829 [EOF]
1830 [exit status: 2]
1831 ");
1832
1833 insta::assert_snapshot!(work_dir.run_jj([
1834 "squash",
1835 "--onto=@",
1836 "--into=@-"
1837 ]), @"
1838 ------- stderr -------
1839 error: the argument '--onto <REVSETS>' cannot be used with '--into <REVSET>'
1840
1841 Usage: jj squash --onto <REVSETS> [FILESETS]...
1842
1843 For more information, try '--help'.
1844 [EOF]
1845 [exit status: 2]
1846 ");
1847
1848 insta::assert_snapshot!(work_dir.run_jj([
1849 "squash",
1850 "--after=@",
1851 "--into=@-"
1852 ]), @"
1853 ------- stderr -------
1854 error: the argument '--insert-after <REVSETS>' cannot be used with '--into <REVSET>'
1855
1856 Usage: jj squash --insert-after <REVSETS> [FILESETS]...
1857
1858 For more information, try '--help'.
1859 [EOF]
1860 [exit status: 2]
1861 ");
1862
1863 insta::assert_snapshot!(work_dir.run_jj([
1864 "squash",
1865 "--before=@-",
1866 "--into=@-"
1867 ]), @"
1868 ------- stderr -------
1869 error: the argument '--insert-before <REVSETS>' cannot be used with '--into <REVSET>'
1870
1871 Usage: jj squash --insert-before <REVSETS> [FILESETS]...
1872
1873 For more information, try '--help'.
1874 [EOF]
1875 [exit status: 2]
1876 ");
1877 }
1878
1879 #[test]
1880 fn test_squash_to_new_commit() -> TestResult {
1881 let mut test_env = TestEnvironment::default();
1882 let edit_script = test_env.set_up_fake_editor();
1883 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1884 let work_dir = test_env.work_dir("repo");
1885
1886 work_dir.write_file("file1", "file1\n");
1887 work_dir.run_jj(["commit", "-m", "file1"]).success();
1888 work_dir.write_file("file2", "file2\n");
1889 work_dir.run_jj(["commit", "-m", "file2"]).success();
1890 work_dir.write_file("file3", "file3\n");
1891 work_dir.run_jj(["commit", "-m", "file3"]).success();
1892 work_dir.write_file("file4", "file4\n");
1893 work_dir.run_jj(["commit", "-m", "file4"]).success();
1894 work_dir
1895 .run_jj(["bookmark", "create", "bm4", "-r", "@-"])
1896 .success();
1897 work_dir
1898 .run_jj(["bookmark", "create", "bm3", "-r", "bm4-"])
1899 .success();
1900 work_dir
1901 .run_jj(["bookmark", "create", "bm2", "-r", "bm3-"])
1902 .success();
1903 work_dir
1904 .run_jj(["bookmark", "create", "bm1", "-r", "bm2-"])
1905 .success();
1906 let setup_opid = work_dir.current_operation_id();
1907
1908 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
1909 @ mzvwutvlkqwt
1910 ○ zsuskulnrvyr bm4 file4
1911 │ A file4
1912 ○ kkmpptxzrspx bm3 file3
1913 │ A file3
1914 ○ rlvkpnrzqnoo bm2 file2
1915 │ A file2
1916 ○ qpvuntsmwlqt bm1 file1
1917 │ A file1
1918 ◆ zzzzzzzzzzzz
1919 [EOF]
1920 ");
1921
1922 // insert the commit before a commit
1923 let output = work_dir.run_jj([
1924 "squash",
1925 "-m",
1926 "file 3&4",
1927 "-f",
1928 "kkmpptxzrspx::",
1929 "--insert-before",
1930 "qpvuntsmwlqt",
1931 ]);
1932 insta::assert_snapshot!(output, @r"
1933 ------- stderr -------
1934 Created new commit kpqxywon f87660dd file 3&4
1935 Rebased 2 descendant commits.
1936 Working copy (@) now at: vzqnnsmr 35736bd0 (empty) (no description set)
1937 Parent commit (@-) : rlvkpnrz 4c273fe2 bm2 bm3 bm4 | file2
1938 [EOF]
1939 ");
1940
1941 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
1942 @ vzqnnsmrxxkw
1943 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
1944 │ A file2
1945 ○ qpvuntsmwlqt bm1 file1
1946 │ A file1
1947 ○ kpqxywonksrl file 3&4
1948 │ A file3
1949 │ A file4
1950 ◆ zzzzzzzzzzzz
1951 [EOF]
1952 ");
1953
1954 // insert the commit after a commit
1955 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1956 let output = work_dir.run_jj([
1957 "squash",
1958 "-m",
1959 "file 3&4",
1960 "-f",
1961 "kkmpptxzrspx::",
1962 "--insert-after",
1963 "qpvuntsmwlqt",
1964 ]);
1965 insta::assert_snapshot!(output, @r"
1966 ------- stderr -------
1967 Created new commit lylxulpl 43cf43eb file 3&4
1968 Rebased 1 descendant commits.
1969 Working copy (@) now at: rsllmpnm 42df41a1 (empty) (no description set)
1970 Parent commit (@-) : rlvkpnrz 3a4b2e8a bm2 bm3 bm4 | file2
1971 [EOF]
1972 ");
1973
1974 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
1975 @ rsllmpnmslon
1976 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
1977 │ A file2
1978 ○ lylxulplsnyw file 3&4
1979 │ A file3
1980 │ A file4
1981 ○ qpvuntsmwlqt bm1 file1
1982 │ A file1
1983 ◆ zzzzzzzzzzzz
1984 [EOF]
1985 ");
1986
1987 // insert the commit onto another
1988 work_dir.run_jj(["op", "restore", &setup_opid]).success();
1989 let output = work_dir.run_jj([
1990 "squash",
1991 "-m",
1992 "file 3&4",
1993 "-f",
1994 "kkmpptxzrspx::",
1995 "--onto",
1996 "qpvuntsmwlqt",
1997 ]);
1998 insta::assert_snapshot!(output, @"
1999 ------- stderr -------
2000 Created new commit uyznsvlq fd4b7c85 file 3&4
2001 Working copy (@) now at: uuqyqztp c2d532a4 (empty) (no description set)
2002 Parent commit (@-) : rlvkpnrz 27974c44 bm2 bm3 bm4 | file2
2003 Added 0 files, modified 0 files, removed 2 files
2004 [EOF]
2005 ");
2006
2007 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2008 @ uuqyqztpptml
2009 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2010 │ A file2
2011 │ ○ uyznsvlquzzm file 3&4
2012 ├─╯ A file3
2013 │ A file4
2014 ○ qpvuntsmwlqt bm1 file1
2015 │ A file1
2016 ◆ zzzzzzzzzzzz
2017 [EOF]
2018 ");
2019
2020 // insert the commit after the source commit
2021 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2022 let output = work_dir.run_jj([
2023 "squash",
2024 "-m",
2025 "file 3&4",
2026 "-f",
2027 "kkmpptxzrspx::",
2028 "--insert-after",
2029 "zsuskulnrvyr",
2030 ]);
2031 insta::assert_snapshot!(output, @r"
2032 ------- stderr -------
2033 Created new commit nmzmmopx c7558c47 file 3&4
2034 Rebased 1 descendant commits.
2035 Working copy (@) now at: pwyqokvy 525d9441 (empty) (no description set)
2036 Parent commit (@-) : nmzmmopx c7558c47 file 3&4
2037 [EOF]
2038 ");
2039
2040 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2041 @ pwyqokvyvunr
2042 ○ nmzmmopxokps file 3&4
2043 │ A file3
2044 │ A file4
2045 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2046 │ A file2
2047 ○ qpvuntsmwlqt bm1 file1
2048 │ A file1
2049 ◆ zzzzzzzzzzzz
2050 [EOF]
2051 ");
2052
2053 // insert the commit before the source commit
2054 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2055 let output = work_dir.run_jj([
2056 "squash",
2057 "-m",
2058 "file 3&4",
2059 "-f",
2060 "kkmpptxzrspx::",
2061 "--insert-before",
2062 "zsuskulnrvyr",
2063 ]);
2064 insta::assert_snapshot!(output, @r"
2065 ------- stderr -------
2066 Created new commit nlrtlrxv c5286eac bm4 | file 3&4
2067 Rebased 1 descendant commits.
2068 Working copy (@) now at: plymsszl faf348e7 (empty) (no description set)
2069 Parent commit (@-) : nlrtlrxv c5286eac bm4 | file 3&4
2070 [EOF]
2071 ");
2072
2073 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2074 @ plymsszllttm
2075 ○ nlrtlrxvuusk bm4 file 3&4
2076 │ A file3
2077 │ A file4
2078 ○ rlvkpnrzqnoo bm2 bm3 file2
2079 │ A file2
2080 ○ qpvuntsmwlqt bm1 file1
2081 │ A file1
2082 ◆ zzzzzzzzzzzz
2083 [EOF]
2084 ");
2085
2086 // double destination with a commit that will disappear
2087 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2088 let output = work_dir.run_jj([
2089 "squash",
2090 "-m",
2091 "file 3&4",
2092 "-f",
2093 "kkmpptxzrspx::",
2094 "--onto",
2095 "rlvkpnrzqnoo",
2096 "--onto",
2097 "kkmpptxzrspx",
2098 ]);
2099 insta::assert_snapshot!(output, @"
2100 ------- stderr -------
2101 Created new commit uuuvxpvw 2ad3f239 file 3&4
2102 Working copy (@) now at: nmpuuozl 95ef3451 (empty) (no description set)
2103 Parent commit (@-) : rlvkpnrz 27974c44 bm2 bm3 bm4 | file2
2104 Added 0 files, modified 0 files, removed 2 files
2105 [EOF]
2106 ");
2107
2108 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2109 @ nmpuuozlonyz
2110 │ ○ uuuvxpvwspwr file 3&4
2111 ├─╯ A file3
2112 │ A file4
2113 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2114 │ A file2
2115 ○ qpvuntsmwlqt bm1 file1
2116 │ A file1
2117 ◆ zzzzzzzzzzzz
2118 [EOF]
2119 ");
2120
2121 // creating a new commit should open the editor to write the commit message
2122 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2123 std::fs::write(edit_script, ["dump editor1", "write\nfile 3&4"].join("\0"))?;
2124 let output = work_dir.run_jj([
2125 "squash",
2126 "-f",
2127 "kkmpptxzrspx::zsuskulnrvyr",
2128 "--insert-before",
2129 "qpvuntsmwlqt",
2130 ]);
2131 insta::assert_snapshot!(output, @r"
2132 ------- stderr -------
2133 Created new commit pkstwlsy 41510a56 file 3&4
2134 Rebased 3 descendant commits.
2135 Working copy (@) now at: mzvwutvl 3d11750f (empty) (no description set)
2136 Parent commit (@-) : rlvkpnrz 8ed73d06 bm2 bm3 bm4 | file2
2137 [EOF]
2138 ");
2139
2140 let editor1 = std::fs::read_to_string(test_env.env_root().join("editor1"))?;
2141 insta::assert_snapshot!(
2142 editor1, @r#"
2143 JJ: Enter a description for the combined commit.
2144
2145 JJ: Description from source commit:
2146 file3
2147
2148 JJ: Description from source commit:
2149 file4
2150
2151 JJ: Change ID: pkstwlsy
2152 JJ: This commit contains the following changes:
2153 JJ: A file3
2154 JJ: A file4
2155 JJ:
2156 JJ: Lines starting with "JJ:" (like this one) will be removed.
2157 "#);
2158
2159 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2160 @ mzvwutvlkqwt
2161 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2162 │ A file2
2163 ○ qpvuntsmwlqt bm1 file1
2164 │ A file1
2165 ○ pkstwlsyuyku file 3&4
2166 │ A file3
2167 │ A file4
2168 ◆ zzzzzzzzzzzz
2169 [EOF]
2170 ");
2171
2172 let output = work_dir.run_jj(["evolog", "-r", "pkstwlsyuyku"]);
2173 insta::assert_snapshot!(output, @"
2174 ○ pkstwlsy [email protected] 2001-02-03 08:05:35 41510a56
2175 ├─╮ file 3&4
2176 │ │ -- operation 5a8916858004 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
2177 │ ○ zsuskuln/0 [email protected] 2001-02-03 08:05:35 a5bc761f (hidden)
2178 │ │ file4
2179 │ │ -- operation 5a8916858004 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
2180 │ ○ zsuskuln/4 [email protected] 2001-02-03 08:05:11 38778966 (hidden)
2181 │ │ file4
2182 │ │ -- operation bc1b588e00d0 commit 89a30a7539466ed176c1ef122a020fd9cb15848e
2183 │ ○ zsuskuln/5 [email protected] 2001-02-03 08:05:11 89a30a75 (hidden)
2184 │ │ (no description set)
2185 │ │ -- operation 0b07b8894eb2 snapshot working copy
2186 │ ○ zsuskuln/6 [email protected] 2001-02-03 08:05:10 bbf04d26 (hidden)
2187 │ (empty) (no description set)
2188 │ -- operation 28d93bc62a97 commit c23c424826221bc4fdee9487926595324e50ee95
2189 ○ kkmpptxz/0 [email protected] 2001-02-03 08:05:35 ce3b0a58 (hidden)
2190 │ file3
2191 │ -- operation 5a8916858004 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
2192 ○ kkmpptxz/3 [email protected] 2001-02-03 08:05:10 0d254956 (hidden)
2193 │ file3
2194 │ -- operation 28d93bc62a97 commit c23c424826221bc4fdee9487926595324e50ee95
2195 ○ kkmpptxz/4 [email protected] 2001-02-03 08:05:10 c23c4248 (hidden)
2196 │ (no description set)
2197 │ -- operation d4b6d8894b8d snapshot working copy
2198 ○ kkmpptxz/5 [email protected] 2001-02-03 08:05:09 c1272e87 (hidden)
2199 (empty) (no description set)
2200 -- operation 24e77086e358 commit cb58ff1c6f1af92f827661e7275941ceb4d910c5
2201 [EOF]
2202 ");
2203
2204 // creating a new commit with --use-destination-message shouldn't open the
2205 // editor
2206 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2207 let output = work_dir.run_jj([
2208 "squash",
2209 "-f",
2210 "kkmpptxzrspx::zsuskulnrvyr",
2211 "--insert-before",
2212 "qpvuntsmwlqt",
2213 "--use-destination-message",
2214 ]);
2215 insta::assert_snapshot!(output, @r"
2216 ------- stderr -------
2217 Created new commit soqnvnyz bf2d3b81 (no description set)
2218 Rebased 3 descendant commits.
2219 Working copy (@) now at: mzvwutvl 9ebad59e (empty) (no description set)
2220 Parent commit (@-) : rlvkpnrz 0c770834 bm2 bm3 bm4 | file2
2221 [EOF]
2222 ");
2223
2224 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2225 @ mzvwutvlkqwt
2226 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2227 │ A file2
2228 ○ qpvuntsmwlqt bm1 file1
2229 │ A file1
2230 ○ soqnvnyzoxuuA file3
2231 │ A file4
2232 ◆ zzzzzzzzzzzz
2233 [EOF]
2234 ");
2235
2236 // squashing 0 sources should create an empty commit
2237 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2238 let output = work_dir.run_jj([
2239 "squash",
2240 "-f",
2241 "none()",
2242 "--insert-before",
2243 "qpvuntsmwlqt",
2244 "--use-destination-message",
2245 ]);
2246 insta::assert_snapshot!(output, @r"
2247 ------- stderr -------
2248 Created new commit nsrwusvy c2183685 (empty) (no description set)
2249 Rebased 5 descendant commits.
2250 Working copy (@) now at: mzvwutvl cb96ecf9 (empty) (no description set)
2251 Parent commit (@-) : zsuskuln 97edce13 bm4 | file4
2252 [EOF]
2253 ");
2254
2255 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2256 @ mzvwutvlkqwt
2257 ○ zsuskulnrvyr bm4 file4
2258 │ A file4
2259 ○ kkmpptxzrspx bm3 file3
2260 │ A file3
2261 ○ rlvkpnrzqnoo bm2 file2
2262 │ A file2
2263 ○ qpvuntsmwlqt bm1 file1
2264 │ A file1
2265 ○ nsrwusvynpoy
2266 ◆ zzzzzzzzzzzz
2267 [EOF]
2268 ");
2269
2270 let output = work_dir.run_jj(["evolog", "-r", "nsrwusvynpoy"]);
2271 insta::assert_snapshot!(output, @"
2272 ○ nsrwusvy [email protected] 2001-02-03 08:05:42 c2183685
2273 (empty) (no description set)
2274 -- operation f492acaa90e1 squash 0 commits
2275 [EOF]
2276 ");
2277
2278 // squashing empty changes should create an empty commit
2279 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2280 let output = work_dir.run_jj([
2281 "squash",
2282 "-f",
2283 "kkmpptxzrspx::zsuskulnrvyr",
2284 "--insert-before",
2285 "qpvuntsmwlqt",
2286 "--use-destination-message",
2287 "no file",
2288 ]);
2289 insta::assert_snapshot!(output, @r"
2290 ------- stderr -------
2291 Warning: No matching entries for paths: no file
2292 Created new commit wtlqussy 7eff41c8 (empty) (no description set)
2293 Rebased 5 descendant commits.
2294 Working copy (@) now at: mzvwutvl cf8a98c4 (empty) (no description set)
2295 Parent commit (@-) : zsuskuln 461e8bb9 bm4 | file4
2296 [EOF]
2297 ");
2298
2299 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2300 @ mzvwutvlkqwt
2301 ○ zsuskulnrvyr bm4 file4
2302 │ A file4
2303 ○ kkmpptxzrspx bm3 file3
2304 │ A file3
2305 ○ rlvkpnrzqnoo bm2 file2
2306 │ A file2
2307 ○ qpvuntsmwlqt bm1 file1
2308 │ A file1
2309 ○ wtlqussytxur
2310 ◆ zzzzzzzzzzzz
2311 [EOF]
2312 ");
2313
2314 let output = work_dir.run_jj(["evolog", "-r", "wtlqussytxur"]);
2315 insta::assert_snapshot!(output, @"
2316 ○ wtlqussy [email protected] 2001-02-03 08:05:46 7eff41c8
2317 (empty) (no description set)
2318 -- operation 607e6cfefd17 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
2319 [EOF]
2320 ");
2321
2322 // squashing from an empty commit should produce an empty commit
2323 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2324 let output = work_dir.run_jj(["new", "--no-edit", "root()"]);
2325 insta::assert_snapshot!(output, @"
2326 ------- stderr -------
2327 Created new commit szrrkvty f5e47d01 (empty) (no description set)
2328 [EOF]
2329 ");
2330
2331 let output = work_dir.run_jj([
2332 "squash",
2333 "-f",
2334 "szrrkvty",
2335 "--onto",
2336 "root()",
2337 "--use-destination-message",
2338 ]);
2339 insta::assert_snapshot!(output, @"
2340 ------- stderr -------
2341 Created new commit pyoswmwk 991d0644 (empty) (no description set)
2342 [EOF]
2343 ");
2344
2345 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2346 @ mzvwutvlkqwt
2347 ○ zsuskulnrvyr bm4 file4
2348 │ A file4
2349 ○ kkmpptxzrspx bm3 file3
2350 │ A file3
2351 ○ rlvkpnrzqnoo bm2 file2
2352 │ A file2
2353 ○ qpvuntsmwlqt bm1 file1
2354 │ A file1
2355 │ ○ pyoswmwkkqyt
2356 ├─╯
2357 ◆ zzzzzzzzzzzz
2358 [EOF]
2359 ");
2360
2361 let output = work_dir.run_jj(["evolog", "-r", "pyoswmwkkqyt"]);
2362 insta::assert_snapshot!(output, @"
2363 ○ pyoswmwk [email protected] 2001-02-03 08:05:50 991d0644
2364 │ (empty) (no description set)
2365 │ -- operation e7931f81c66a squash commit f5e47d019271a392eb7f92a6b2e9f8cf41d97049
2366 ○ szrrkvty/0 [email protected] 2001-02-03 08:05:50 f5e47d01 (hidden)
2367 (empty) (no description set)
2368 -- operation cffbaf4787d4 new empty commit
2369 [EOF]
2370 ");
2371
2372 // --before and --after together
2373 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2374 let output = work_dir.run_jj([
2375 "squash",
2376 "-m",
2377 "file 3&4",
2378 "-f",
2379 "kkmpptxzrspx::",
2380 "--insert-after",
2381 "root()",
2382 "--insert-before",
2383 "rlvkpnrzqnoo",
2384 ]);
2385 insta::assert_snapshot!(output, @r"
2386 ------- stderr -------
2387 Created new commit vkywoywq 96673776 file 3&4
2388 Rebased 1 descendant commits.
2389 Working copy (@) now at: rsmzzqvr e37e3e4a (empty) (no description set)
2390 Parent commit (@-) : rlvkpnrz 8044909c bm2 bm3 bm4 | file2
2391 [EOF]
2392 ");
2393
2394 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2395 @ rsmzzqvrnpvn
2396 ○ rlvkpnrzqnoo bm2 bm3 bm4 file2
2397 ├─╮ A file2
2398 │ ○ vkywoywqymtr file 3&4
2399 │ │ A file3
2400 │ │ A file4
2401 ○ │ qpvuntsmwlqt bm1 file1
2402 ├─╯ A file1
2403 ◆ zzzzzzzzzzzz
2404 [EOF]
2405 ");
2406
2407 // squash-moves can use the current commit too
2408 work_dir.run_jj(["op", "restore", &setup_opid]).success();
2409 work_dir.run_jj(["edit", "bm3"]).success();
2410 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2411 ○ zsuskulnrvyr bm4 file4
2412 │ A file4
2413 @ kkmpptxzrspx bm3 file3
2414 │ A file3
2415 ○ rlvkpnrzqnoo bm2 file2
2416 │ A file2
2417 ○ qpvuntsmwlqt bm1 file1
2418 │ A file1
2419 ◆ zzzzzzzzzzzz
2420 [EOF]
2421 ");
2422 insta::assert_snapshot!(work_dir.run_jj(["squash", "--before", "rlvkpnrzqnoo"]), @r"
2423 ------- stderr -------
2424 Created new commit wxzmtyol bc0392dc file3
2425 Rebased 2 descendant commits.
2426 Working copy (@) now at: musouqkq 1841cc81 (empty) (no description set)
2427 Parent commit (@-) : rlvkpnrz 264a43af bm2 bm3 | file2
2428 [EOF]
2429 ");
2430 insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
2431 @ musouqkqsmll
2432 │ ○ zsuskulnrvyr bm4 file4
2433 ├─╯ A file4
2434 ○ rlvkpnrzqnoo bm2 bm3 file2
2435 │ A file2
2436 ○ wxzmtyollrwl file3
2437 │ A file3
2438 ○ qpvuntsmwlqt bm1 file1
2439 │ A file1
2440 ◆ zzzzzzzzzzzz
2441 [EOF]
2442 ");
2443 Ok(())
2444 }
2445
2446 #[test]
2447 fn test_squash_with_editor_combine_messages() -> TestResult {
2448 let mut test_env = TestEnvironment::default();
2449 let edit_script = test_env.set_up_fake_editor();
2450 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2451 let work_dir = test_env.work_dir("repo");
2452
2453 work_dir.run_jj(["describe", "-m", "destination"]).success();
2454 work_dir.write_file("file1", "a\n");
2455 work_dir.run_jj(["new", "-m", "source"]).success();
2456 work_dir.write_file("file1", "b\n");
2457
2458 // Both source and destination have descriptions, so editor will open to combine
2459 // them; the --editor was superfluous.
2460 std::fs::write(
2461 &edit_script,
2462 ["dump editor", "write\nfinal description from editor"].join("\0"),
2463 )?;
2464 work_dir.run_jj(["squash", "--editor"]).success();
2465
2466 // Verify editor was opened once with combined messages
2467 let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
2468 insta::assert_snapshot!(
2469 editor, @r#"
2470 JJ: Enter a description for the combined commit.
2471 JJ: Description from the destination commit:
2472 destination
2473
2474 JJ: Description from source commit:
2475 source
2476
2477 JJ: Change ID: qpvuntsm
2478 JJ: This commit contains the following changes:
2479 JJ: A file1
2480 JJ:
2481 JJ: Lines starting with "JJ:" (like this one) will be removed.
2482 "#);
2483
2484 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
2485 final description from editor
2486 [EOF]
2487 ");
2488 Ok(())
2489 }
2490
2491 #[test]
2492 fn test_squash_with_editor_and_message_args() -> TestResult {
2493 let mut test_env = TestEnvironment::default();
2494 let edit_script = test_env.set_up_fake_editor();
2495 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2496 let work_dir = test_env.work_dir("repo");
2497
2498 work_dir.run_jj(["describe", "-m", "destination"]).success();
2499 work_dir.write_file("file1", "a\n");
2500 work_dir.run_jj(["new"]).success();
2501 work_dir.write_file("file1", "b\n");
2502
2503 std::fs::write(&edit_script, "dump editor")?;
2504 work_dir
2505 .run_jj(["squash", "-m", "message from command line", "--editor"])
2506 .success();
2507
2508 // Verify editor was opened with the message from command line
2509 let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
2510 insta::assert_snapshot!(
2511 editor, @r#"
2512 message from command line
2513
2514 JJ: Change ID: qpvuntsm
2515 JJ: This commit contains the following changes:
2516 JJ: A file1
2517 JJ:
2518 JJ: Lines starting with "JJ:" (like this one) will be removed.
2519 "#);
2520 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
2521 message from command line
2522 [EOF]
2523 ");
2524 Ok(())
2525 }
2526
2527 #[test]
2528 fn test_squash_with_editor_and_empty_message() -> TestResult {
2529 let mut test_env = TestEnvironment::default();
2530 let edit_script = test_env.set_up_fake_editor();
2531 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
2532 let work_dir = test_env.work_dir("repo");
2533
2534 work_dir.run_jj(["describe", "-m", "destination"]).success();
2535 work_dir.write_file("file1", "a\n");
2536 work_dir.run_jj(["new"]).success();
2537 work_dir.write_file("file1", "b\n");
2538
2539 // Use --editor with an empty message. The trailers should be added because
2540 // the editor will be opened.
2541 std::fs::write(&edit_script, "dump editor")?;
2542 work_dir
2543 .run_jj([
2544 "squash",
2545 "-m",
2546 "",
2547 "--editor",
2548 "--config",
2549 r#"templates.commit_trailers='"Trailer: value"'"#,
2550 ])
2551 .success();
2552
2553 // Verify editor was opened with trailers added to the empty message
2554 let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
2555 insta::assert_snapshot!(
2556 editor, @r#"
2557
2558
2559 Trailer: value
2560
2561 JJ: Change ID: qpvuntsm
2562 JJ: This commit contains the following changes:
2563 JJ: A file1
2564 JJ:
2565 JJ: Lines starting with "JJ:" (like this one) will be removed.
2566 "#);
2567 insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
2568 Trailer: value
2569 [EOF]
2570 ");
2571 Ok(())
2572 }
2573
2574 #[must_use]
2575 fn get_description(work_dir: &TestWorkDir, rev: &str) -> CommandOutput {
2576 work_dir.run_jj(["log", "--no-graph", "-T", "description", "-r", rev])
2577 }
2578
2579 #[must_use]
2580 fn get_log_output_with_description(work_dir: &TestWorkDir) -> CommandOutput {
2581 let template = r#"separate(" ", commit_id.short(), description)"#;
2582 work_dir.run_jj(["log", "-T", template])
2583 }
2584
2585 #[must_use]
2586 fn get_log_with_summary(work_dir: &TestWorkDir) -> CommandOutput {
2587 let template = r#"separate(" ", change_id.short(), local_bookmarks, description)"#;
2588 work_dir.run_jj(["log", "-T", template, "--summary"])
2589 }