just playing with tangled
at ig/vimdiffwarn 905 lines 31 kB view 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 15use std::path::PathBuf; 16 17use indoc::indoc; 18 19use crate::common::CommandOutput; 20use crate::common::TestEnvironment; 21use crate::common::TestWorkDir; 22 23#[test] 24fn test_describe() { 25 let mut test_env = TestEnvironment::default(); 26 let edit_script = test_env.set_up_fake_editor(); 27 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 28 let work_dir = test_env.work_dir("repo"); 29 30 // Set a description using `-m` flag 31 let output = work_dir.run_jj(["describe", "-m", "description from CLI"]); 32 insta::assert_snapshot!(output, @r" 33 ------- stderr ------- 34 Working copy (@) now at: qpvuntsm 95979928 (empty) description from CLI 35 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 36 [EOF] 37 "); 38 39 // Set the same description using `-m` flag, but with explicit newline 40 let output = work_dir.run_jj(["describe", "-m", "description from CLI\n"]); 41 insta::assert_snapshot!(output, @r" 42 ------- stderr ------- 43 Nothing changed. 44 [EOF] 45 "); 46 47 // Check that the text file gets initialized with the current description and 48 // make no changes 49 std::fs::write(&edit_script, "dump editor0").unwrap(); 50 let output = work_dir.run_jj(["describe"]); 51 insta::assert_snapshot!(output, @r" 52 ------- stderr ------- 53 Nothing changed. 54 [EOF] 55 "); 56 insta::assert_snapshot!( 57 std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#" 58 description from CLI 59 60 JJ: Lines starting with "JJ:" (like this one) will be removed. 61 "#); 62 63 // Set a description in editor 64 std::fs::write(&edit_script, "write\ndescription from editor").unwrap(); 65 let output = work_dir.run_jj(["describe"]); 66 insta::assert_snapshot!(output, @r" 67 ------- stderr ------- 68 Working copy (@) now at: qpvuntsm 94fcb906 (empty) description from editor 69 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 70 [EOF] 71 "); 72 73 // Lines in editor starting with "JJ: " are ignored 74 std::fs::write( 75 &edit_script, 76 "write\nJJ: ignored\ndescription among comment\nJJ: ignored", 77 ) 78 .unwrap(); 79 let output = work_dir.run_jj(["describe"]); 80 insta::assert_snapshot!(output, @r" 81 ------- stderr ------- 82 Working copy (@) now at: qpvuntsm 7a348923 (empty) description among comment 83 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 84 [EOF] 85 "); 86 87 // Multi-line description 88 std::fs::write(&edit_script, "write\nline1\nline2\n\nline4\n\n").unwrap(); 89 let output = work_dir.run_jj(["describe"]); 90 insta::assert_snapshot!(output, @r" 91 ------- stderr ------- 92 Working copy (@) now at: qpvuntsm 749361b5 (empty) line1 93 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 94 [EOF] 95 "); 96 let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-Tdescription"]); 97 insta::assert_snapshot!(output, @r" 98 line1 99 line2 100 101 line4 102 [EOF] 103 "); 104 105 // Multi-line description again with CRLF, which should make no changes 106 std::fs::write(&edit_script, "write\nline1\r\nline2\r\n\r\nline4\r\n\r\n").unwrap(); 107 let output = work_dir.run_jj(["describe"]); 108 insta::assert_snapshot!(output, @r" 109 ------- stderr ------- 110 Nothing changed. 111 [EOF] 112 "); 113 114 // Multi-line description starting with newlines 115 std::fs::write(&edit_script, "write\n\n\nline1\nline2").unwrap(); 116 let output = work_dir.run_jj(["describe"]); 117 insta::assert_snapshot!(output, @r" 118 ------- stderr ------- 119 Working copy (@) now at: qpvuntsm dc44dbee (empty) line1 120 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 121 [EOF] 122 "); 123 let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-Tdescription"]); 124 insta::assert_snapshot!(output, @r" 125 line1 126 line2 127 [EOF] 128 "); 129 130 // Clear description 131 let output = work_dir.run_jj(["describe", "-m", ""]); 132 insta::assert_snapshot!(output, @r" 133 ------- stderr ------- 134 Working copy (@) now at: qpvuntsm 6296963b (empty) (no description set) 135 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 136 [EOF] 137 "); 138 std::fs::write(&edit_script, "write\n").unwrap(); 139 let output = work_dir.run_jj(["describe"]); 140 insta::assert_snapshot!(output, @r" 141 ------- stderr ------- 142 Nothing changed. 143 [EOF] 144 "); 145 146 // Fails if the editor fails 147 std::fs::write(&edit_script, "fail").unwrap(); 148 let output = work_dir.run_jj(["describe"]); 149 insta::with_settings!({ 150 filters => [ 151 (r"\bEditor '[^']*'", "Editor '<redacted>'"), 152 (r"\b(editor-)[^.]*(\.jjdescription)\b", "$1<redacted>$2"), 153 ("exit code", "exit status"), // Windows 154 ], 155 }, { 156 insta::assert_snapshot!(output, @r" 157 ------- stderr ------- 158 Error: Failed to edit description 159 Caused by: Editor '<redacted>' exited with exit status: 1 160 Hint: Edited description is left in $TEST_ENV/repo/.jj/repo/editor-<redacted>.jjdescription 161 [EOF] 162 [exit status: 1] 163 "); 164 }); 165 166 // ignore everything after the first ignore-rest line 167 std::fs::write( 168 &edit_script, 169 indoc! {" 170 write 171 description from editor 172 173 content of message from editor 174 JJ: ignore-rest 175 content after ignore line should not be included 176 JJ: ignore-rest 177 ignore everything until EOF or next description 178 "}, 179 ) 180 .unwrap(); 181 let output = work_dir.run_jj(["describe"]); 182 insta::assert_snapshot!(output, @r" 183 ------- stderr ------- 184 Working copy (@) now at: qpvuntsm 10fa2dc7 (empty) description from editor 185 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 186 [EOF] 187 "); 188 let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-Tdescription"]); 189 insta::assert_snapshot!(output, @r" 190 description from editor 191 192 content of message from editor 193 [EOF] 194 "); 195} 196 197#[test] 198fn test_describe_editor_env() { 199 let test_env = TestEnvironment::default(); 200 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 201 let work_dir = test_env.work_dir("repo"); 202 203 // Fails if the editor doesn't exist 204 let output = work_dir.run_jj_with(|cmd| { 205 cmd.arg("describe") 206 .env("EDITOR", "this-editor-does-not-exist") 207 }); 208 insta::assert_snapshot!( 209 output.normalize_stderr_with(|s| s.split_inclusive('\n').take(3).collect()), @r" 210 ------- stderr ------- 211 Error: Failed to edit description 212 Caused by: 213 1: Failed to run editor 'this-editor-does-not-exist' 214 [EOF] 215 [exit status: 1] 216 "); 217 218 // `$VISUAL` overrides `$EDITOR` 219 let output = work_dir.run_jj_with(|cmd| { 220 cmd.arg("describe") 221 .env("VISUAL", "bad-editor-from-visual-env") 222 .env("EDITOR", "bad-editor-from-editor-env") 223 }); 224 insta::assert_snapshot!( 225 output.normalize_stderr_with(|s| s.split_inclusive('\n').take(3).collect()), @r" 226 ------- stderr ------- 227 Error: Failed to edit description 228 Caused by: 229 1: Failed to run editor 'bad-editor-from-visual-env' 230 [EOF] 231 [exit status: 1] 232 "); 233 234 // `ui.editor` config overrides `$VISUAL` 235 test_env.add_config(r#"ui.editor = "bad-editor-from-config""#); 236 let output = work_dir.run_jj_with(|cmd| { 237 cmd.arg("describe") 238 .env("VISUAL", "bad-editor-from-visual-env") 239 }); 240 insta::assert_snapshot!( 241 output.normalize_stderr_with(|s| s.split_inclusive('\n').take(3).collect()), @r" 242 ------- stderr ------- 243 Error: Failed to edit description 244 Caused by: 245 1: Failed to run editor 'bad-editor-from-config' 246 [EOF] 247 [exit status: 1] 248 "); 249 250 // `$JJ_EDITOR` overrides `ui.editor` config 251 let output = work_dir.run_jj_with(|cmd| { 252 cmd.arg("describe") 253 .env("JJ_EDITOR", "bad-jj-editor-from-jj-editor-env") 254 }); 255 insta::assert_snapshot!( 256 output.normalize_stderr_with(|s| s.split_inclusive('\n').take(3).collect()), @r" 257 ------- stderr ------- 258 Error: Failed to edit description 259 Caused by: 260 1: Failed to run editor 'bad-jj-editor-from-jj-editor-env' 261 [EOF] 262 [exit status: 1] 263 "); 264} 265 266#[test] 267fn test_describe_multiple_commits() { 268 let mut test_env = TestEnvironment::default(); 269 let edit_script = test_env.set_up_fake_editor(); 270 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 271 let work_dir = test_env.work_dir("repo"); 272 273 // Initial setup 274 work_dir.run_jj(["new"]).success(); 275 work_dir.run_jj(["new"]).success(); 276 insta::assert_snapshot!(get_log_output(&work_dir), @r" 277 @ c6349e79bbfd 278 ○ 65b6b74e0897 279 ○ 230dd059e1b0 280 ◆ 000000000000 281 [EOF] 282 "); 283 284 // Set the description of multiple commits using `-m` flag 285 let output = work_dir.run_jj(["describe", "-r@", "-r@--", "-m", "description from CLI"]); 286 insta::assert_snapshot!(output, @r" 287 ------- stderr ------- 288 Updated 2 commits 289 Rebased 1 descendant commits 290 Working copy (@) now at: kkmpptxz 41659b84 (empty) description from CLI 291 Parent commit (@-) : rlvkpnrz 8d650510 (empty) (no description set) 292 [EOF] 293 "); 294 insta::assert_snapshot!(get_log_output(&work_dir), @r" 295 @ 41659b846096 description from CLI 296 ○ 8d650510daad 297 ○ a42f5755e688 description from CLI 298 ◆ 000000000000 299 [EOF] 300 "); 301 302 // Check that the text file gets initialized with the current description of 303 // each commit and doesn't update commits if no changes are made. 304 // Commit descriptions are edited in topological order 305 std::fs::write(&edit_script, "dump editor0").unwrap(); 306 let output = work_dir.run_jj(["describe", "-r@", "@-"]); 307 insta::assert_snapshot!(output, @r" 308 ------- stderr ------- 309 Nothing changed. 310 [EOF] 311 "); 312 insta::assert_snapshot!( 313 std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#" 314 JJ: Enter or edit commit descriptions after the `JJ: describe` lines. 315 JJ: Warning: 316 JJ: - The text you enter will be lost on a syntax error. 317 JJ: - The syntax of the separator lines may change in the future. 318 JJ: 319 JJ: describe 8d650510daad ------- 320 321 322 JJ: describe 41659b846096 ------- 323 description from CLI 324 325 JJ: Lines starting with "JJ:" (like this one) will be removed. 326 "#); 327 328 // Set the description of multiple commits in the editor 329 std::fs::write( 330 &edit_script, 331 indoc! {" 332 write 333 JJ: Enter or edit commit descriptions after the `JJ: describe` lines. 334 335 JJ: More header tests. Library tests verify parsing in other situations. 336 337 JJ: describe 8d650510daad ------- 338 description from editor of @- 339 340 further commit message of @- 341 342 JJ: describe 41659b846096 ------- 343 description from editor of @ 344 345 further commit message of @ 346 347 JJ: Lines starting with \"JJ: \" (like this one) will be removed. 348 "}, 349 ) 350 .unwrap(); 351 let output = work_dir.run_jj(["describe", "@", "@-"]); 352 insta::assert_snapshot!(output, @r" 353 ------- stderr ------- 354 Updated 2 commits 355 Working copy (@) now at: kkmpptxz f203494a (empty) description from editor of @ 356 Parent commit (@-) : rlvkpnrz 0d76a92c (empty) description from editor of @- 357 [EOF] 358 "); 359 insta::assert_snapshot!(get_log_output(&work_dir), @r" 360 @ f203494a4507 description from editor of @ 361362 │ further commit message of @ 363 ○ 0d76a92ca7cc description from editor of @- 364365 │ further commit message of @- 366 ○ a42f5755e688 description from CLI 367 ◆ 000000000000 368 [EOF] 369 "); 370 371 // Fails if the edited message has a commit with multiple descriptions 372 std::fs::write( 373 &edit_script, 374 indoc! {" 375 write 376 JJ: describe 0d76a92ca7cc ------- 377 first description from editor of @- 378 379 further commit message of @- 380 381 JJ: describe 0d76a92ca7cc ------- 382 second description from editor of @- 383 384 further commit message of @- 385 386 JJ: describe f203494a4507 ------- 387 updated description from editor of @ 388 389 further commit message of @ 390 391 JJ: Lines starting with \"JJ: \" (like this one) will be removed. 392 "}, 393 ) 394 .unwrap(); 395 let output = work_dir.run_jj(["describe", "@", "@-"]); 396 insta::assert_snapshot!(output, @r" 397 ------- stderr ------- 398 Error: The following commits were found in the edited message multiple times: 0d76a92ca7cc 399 [EOF] 400 [exit status: 1] 401 "); 402 403 // Fails if the edited message has unexpected commit IDs 404 std::fs::write( 405 &edit_script, 406 indoc! {" 407 write 408 JJ: describe 000000000000 ------- 409 unexpected commit ID 410 411 JJ: describe 0d76a92ca7cc ------- 412 description from editor of @- 413 414 further commit message of @- 415 416 JJ: describe f203494a4507 ------- 417 description from editor of @ 418 419 further commit message of @ 420 421 JJ: Lines starting with \"JJ: \" (like this one) will be removed. 422 "}, 423 ) 424 .unwrap(); 425 let output = work_dir.run_jj(["describe", "@", "@-"]); 426 insta::assert_snapshot!(output, @r" 427 ------- stderr ------- 428 Error: The following commits were not being edited, but were found in the edited message: 000000000000 429 [EOF] 430 [exit status: 1] 431 "); 432 433 // Fails if the edited message has missing commit messages 434 std::fs::write( 435 &edit_script, 436 indoc! {" 437 write 438 JJ: describe f203494a4507 ------- 439 description from editor of @ 440 441 further commit message of @ 442 443 JJ: Lines starting with \"JJ: \" (like this one) will be removed. 444 "}, 445 ) 446 .unwrap(); 447 let output = work_dir.run_jj(["describe", "@", "@-"]); 448 insta::assert_snapshot!(output, @r" 449 ------- stderr ------- 450 Error: The description for the following commits were not found in the edited message: 0d76a92ca7cc 451 [EOF] 452 [exit status: 1] 453 "); 454 455 // Fails if the edited message has a line which does not have any preceding 456 // `JJ: describe` headers 457 std::fs::write( 458 &edit_script, 459 indoc! {" 460 write 461 description from editor of @- 462 463 JJ: describe f203494a4507 ------- 464 description from editor of @ 465 466 JJ: Lines starting with \"JJ: \" (like this one) will be removed. 467 "}, 468 ) 469 .unwrap(); 470 let output = work_dir.run_jj(["describe", "@", "@-"]); 471 insta::assert_snapshot!(output, @r#" 472 ------- stderr ------- 473 Error: Found the following line without a commit header: "description from editor of @-" 474 [EOF] 475 [exit status: 1] 476 "#); 477 478 // Fails if the editor fails 479 std::fs::write(&edit_script, "fail").unwrap(); 480 let output = work_dir.run_jj(["describe", "@", "@-"]); 481 insta::with_settings!({ 482 filters => [ 483 (r"\bEditor '[^']*'", "Editor '<redacted>'"), 484 (r"\b(editor-)[^.]*(\.jjdescription)\b", "$1<redacted>$2"), 485 ("exit code", "exit status"), // Windows 486 ], 487 }, { 488 insta::assert_snapshot!(output, @r" 489 ------- stderr ------- 490 Error: Failed to edit description 491 Caused by: Editor '<redacted>' exited with exit status: 1 492 Hint: Edited description is left in $TEST_ENV/repo/.jj/repo/editor-<redacted>.jjdescription 493 [EOF] 494 [exit status: 1] 495 "); 496 }); 497 498 // describe lines should take priority over ignore-rest 499 std::fs::write( 500 &edit_script, 501 indoc! {" 502 write 503 JJ: describe 0d76a92ca7cc ------- 504 description from editor for @- 505 506 JJ: ignore-rest 507 content after ignore-rest should not be included 508 509 JJ: describe a42f5755e688 ------- 510 description from editor for @-- 511 512 JJ: ignore-rest 513 each commit should skip their own ignore-rest 514 "}, 515 ) 516 .unwrap(); 517 let output = work_dir.run_jj(["describe", "@-", "@--"]); 518 insta::assert_snapshot!(output, @r" 519 ------- stderr ------- 520 Updated 2 commits 521 Rebased 1 descendant commits 522 Working copy (@) now at: kkmpptxz 1d7701ee (empty) description from editor of @ 523 Parent commit (@-) : rlvkpnrz 5389926e (empty) description from editor for @- 524 [EOF] 525 "); 526 insta::assert_snapshot!(get_log_output(&work_dir), @r" 527 @ 1d7701eec9bc description from editor of @ 528529 │ further commit message of @ 530 ○ 5389926ebed6 description from editor for @- 531 ○ eaa8547ae37a description from editor for @-- 532 ◆ 000000000000 533 [EOF] 534 "); 535} 536 537#[test] 538fn test_multiple_message_args() { 539 let test_env = TestEnvironment::default(); 540 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 541 let work_dir = test_env.work_dir("repo"); 542 543 // Set a description using `-m` flag 544 let output = work_dir.run_jj([ 545 "describe", 546 "-m", 547 "First Paragraph from CLI", 548 "-m", 549 "Second Paragraph from CLI", 550 ]); 551 insta::assert_snapshot!(output, @r" 552 ------- stderr ------- 553 Working copy (@) now at: qpvuntsm 99a36a50 (empty) First Paragraph from CLI 554 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 555 [EOF] 556 "); 557 558 let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-Tdescription"]); 559 insta::assert_snapshot!(output, @r" 560 First Paragraph from CLI 561 562 Second Paragraph from CLI 563 [EOF] 564 "); 565 566 // Set the same description, with existing newlines 567 let output = work_dir.run_jj([ 568 "describe", 569 "-m", 570 "First Paragraph from CLI\n", 571 "-m", 572 "Second Paragraph from CLI\n", 573 ]); 574 insta::assert_snapshot!(output, @r" 575 ------- stderr ------- 576 Nothing changed. 577 [EOF] 578 "); 579 580 // Use an empty -m flag between paragraphs to insert an extra blank line 581 let output = work_dir.run_jj([ 582 "describe", 583 "-m", 584 "First Paragraph from CLI\n", 585 "--message", 586 "", 587 "-m", 588 "Second Paragraph from CLI", 589 ]); 590 insta::assert_snapshot!(output, @r" 591 ------- stderr ------- 592 Working copy (@) now at: qpvuntsm 01ac40b3 (empty) First Paragraph from CLI 593 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 594 [EOF] 595 "); 596 597 let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-Tdescription"]); 598 insta::assert_snapshot!(output, @r" 599 First Paragraph from CLI 600 601 602 Second Paragraph from CLI 603 [EOF] 604 "); 605} 606 607#[test] 608fn test_describe_default_description() { 609 let mut test_env = TestEnvironment::default(); 610 let edit_script = test_env.set_up_fake_editor(); 611 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 612 test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#); 613 let work_dir = test_env.work_dir("repo"); 614 615 work_dir.write_file("file1", "foo\n"); 616 work_dir.write_file("file2", "bar\n"); 617 std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap(); 618 let output = work_dir.run_jj(["describe"]); 619 insta::assert_snapshot!(output, @r" 620 ------- stderr ------- 621 Working copy (@) now at: qpvuntsm 573b6df5 TESTED=TODO 622 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 623 [EOF] 624 "); 625 insta::assert_snapshot!( 626 std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#" 627 TESTED=TODO 628 629 JJ: This commit contains the following changes: 630 JJ: A file1 631 JJ: A file2 632 JJ: 633 JJ: Lines starting with "JJ:" (like this one) will be removed. 634 "#); 635} 636 637#[test] 638fn test_describe_author() { 639 let mut test_env = TestEnvironment::default(); 640 let edit_script = test_env.set_up_fake_editor(); 641 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 642 let work_dir = test_env.work_dir("repo"); 643 644 std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap(); 645 646 test_env.add_config(indoc! {r#" 647 [template-aliases] 648 'format_signature(signature)' = 'signature.name() ++ " " ++ signature.email() ++ " " ++ signature.timestamp()' 649 650 [templates] 651 draft_commit_description = ''' 652 concat( 653 description, 654 "\n", 655 indent( 656 "JJ: ", 657 concat( 658 "Author: " ++ format_detailed_signature(author) ++ "\n", 659 "Committer: " ++ format_detailed_signature(committer) ++ "\n", 660 "\n", 661 diff.stat(76), 662 ), 663 ), 664 ) 665 ''' 666 "#}); 667 let get_signatures = || { 668 let template = r#"format_signature(author) ++ "\n" ++ format_signature(committer)"#; 669 work_dir.run_jj(["log", "-r..", "-T", template]) 670 }; 671 672 // Initial setup 673 work_dir.run_jj(["new"]).success(); 674 work_dir.run_jj(["new"]).success(); 675 work_dir.run_jj(["new"]).success(); 676 insta::assert_snapshot!(get_signatures(), @r" 677 @ Test User test.user@example.com 2001-02-03 04:05:10.000 +07:00 678 │ Test User test.user@example.com 2001-02-03 04:05:10.000 +07:00 679 ○ Test User test.user@example.com 2001-02-03 04:05:09.000 +07:00 680 │ Test User test.user@example.com 2001-02-03 04:05:09.000 +07:00 681 ○ Test User test.user@example.com 2001-02-03 04:05:08.000 +07:00 682 │ Test User test.user@example.com 2001-02-03 04:05:08.000 +07:00 683 ○ Test User test.user@example.com 2001-02-03 04:05:07.000 +07:00 684 │ Test User test.user@example.com 2001-02-03 04:05:07.000 +07:00 685 ~ 686 [EOF] 687 "); 688 689 // Change the author for the latest commit (the committer is always reset) 690 work_dir 691 .run_jj([ 692 "describe", 693 "--author", 694 "Super Seeder <super.seeder@example.com>", 695 ]) 696 .success(); 697 insta::assert_snapshot!(get_signatures(), @r" 698 @ Super Seeder super.seeder@example.com 2001-02-03 04:05:12.000 +07:00 699 │ Test User test.user@example.com 2001-02-03 04:05:12.000 +07:00 700 ○ Test User test.user@example.com 2001-02-03 04:05:09.000 +07:00 701 │ Test User test.user@example.com 2001-02-03 04:05:09.000 +07:00 702 ○ Test User test.user@example.com 2001-02-03 04:05:08.000 +07:00 703 │ Test User test.user@example.com 2001-02-03 04:05:08.000 +07:00 704 ○ Test User test.user@example.com 2001-02-03 04:05:07.000 +07:00 705 │ Test User test.user@example.com 2001-02-03 04:05:07.000 +07:00 706 ~ 707 [EOF] 708 "); 709 insta::assert_snapshot!( 710 std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#" 711 JJ: Author: Super Seeder <super.seeder@example.com> (2001-02-03 08:05:12) 712 JJ: Committer: Test User <test.user@example.com> (2001-02-03 08:05:12) 713 714 JJ: 0 files changed, 0 insertions(+), 0 deletions(-) 715 JJ: 716 JJ: Lines starting with "JJ:" (like this one) will be removed. 717 "#); 718 719 // Change the author for multiple commits (the committer is always reset) 720 work_dir 721 .run_jj([ 722 "describe", 723 "@---", 724 "@-", 725 "--no-edit", 726 "--author", 727 "Super Seeder <super.seeder@example.com>", 728 ]) 729 .success(); 730 insta::assert_snapshot!(get_signatures(), @r" 731 @ Super Seeder super.seeder@example.com 2001-02-03 04:05:12.000 +07:00 732 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 733 ○ Super Seeder super.seeder@example.com 2001-02-03 04:05:14.000 +07:00 734 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 735 ○ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 736 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 737 ○ Super Seeder super.seeder@example.com 2001-02-03 04:05:14.000 +07:00 738 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 739 ~ 740 [EOF] 741 "); 742 743 // Reset the author for the latest commit (the committer is always reset) 744 work_dir 745 .run_jj([ 746 "describe", 747 "--config=user.name=Ove Ridder", 748 "--config=user.email=ove.ridder@example.com", 749 "--no-edit", 750 "--reset-author", 751 ]) 752 .success(); 753 insta::assert_snapshot!(get_signatures(), @r" 754 @ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:16.000 +07:00 755 │ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:16.000 +07:00 756 ○ Super Seeder super.seeder@example.com 2001-02-03 04:05:14.000 +07:00 757 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 758 ○ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 759 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 760 ○ Super Seeder super.seeder@example.com 2001-02-03 04:05:14.000 +07:00 761 │ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 762 ~ 763 [EOF] 764 "); 765 766 // Reset the author for multiple commits (the committer is always reset) 767 work_dir 768 .run_jj([ 769 "describe", 770 "@---", 771 "@-", 772 "--config=user.name=Ove Ridder", 773 "--config=user.email=ove.ridder@example.com", 774 "--reset-author", 775 ]) 776 .success(); 777 insta::assert_snapshot!(get_signatures(), @r" 778 @ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 779 │ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 780 ○ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 781 │ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 782 ○ Test User test.user@example.com 2001-02-03 04:05:14.000 +07:00 783 │ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 784 ○ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 785 │ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:18.000 +07:00 786 ~ 787 [EOF] 788 "); 789 insta::assert_snapshot!( 790 std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#" 791 JJ: Enter or edit commit descriptions after the `JJ: describe` lines. 792 JJ: Warning: 793 JJ: - The text you enter will be lost on a syntax error. 794 JJ: - The syntax of the separator lines may change in the future. 795 JJ: 796 JJ: describe eae86afaa20c ------- 797 798 JJ: Author: Ove Ridder <ove.ridder@example.com> (2001-02-03 08:05:18) 799 JJ: Committer: Ove Ridder <ove.ridder@example.com> (2001-02-03 08:05:18) 800 801 JJ: 0 files changed, 0 insertions(+), 0 deletions(-) 802 JJ: 803 JJ: describe ba485659f76a ------- 804 805 JJ: Author: Ove Ridder <ove.ridder@example.com> (2001-02-03 08:05:18) 806 JJ: Committer: Ove Ridder <ove.ridder@example.com> (2001-02-03 08:05:18) 807 808 JJ: 0 files changed, 0 insertions(+), 0 deletions(-) 809 JJ: 810 JJ: Lines starting with "JJ:" (like this one) will be removed. 811 "#); 812} 813 814#[test] 815fn test_describe_avoids_unc() { 816 let mut test_env = TestEnvironment::default(); 817 let edit_script = test_env.set_up_fake_editor(); 818 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 819 let work_dir = test_env.work_dir("repo"); 820 821 std::fs::write(edit_script, "dump-path path").unwrap(); 822 work_dir.run_jj(["describe"]).success(); 823 824 let edited_path = 825 PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path")).unwrap()); 826 // While `assert!(!edited_path.starts_with("//?/"))` could work here in most 827 // cases, it fails when it is not safe to strip the prefix, such as paths 828 // over 260 chars. 829 assert_eq!(edited_path, dunce::simplified(&edited_path)); 830} 831 832#[test] 833fn test_describe_with_edit_and_message_args_opens_editor() { 834 let mut test_env = TestEnvironment::default(); 835 let edit_script = test_env.set_up_fake_editor(); 836 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 837 let work_dir = test_env.work_dir("repo"); 838 839 std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap(); 840 let output = work_dir.run_jj(["describe", "-m", "message from command line", "--edit"]); 841 insta::assert_snapshot!(output, @r" 842 ------- stderr ------- 843 Working copy (@) now at: qpvuntsm 61ece7a9 (empty) message from command line 844 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 845 [EOF] 846 "); 847 insta::assert_snapshot!( 848 std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#" 849 message from command line 850 851 JJ: Lines starting with "JJ:" (like this one) will be removed. 852 "#); 853} 854 855#[test] 856fn test_describe_change_with_existing_message_with_edit_and_message_args_opens_editor() { 857 let mut test_env = TestEnvironment::default(); 858 let edit_script = test_env.set_up_fake_editor(); 859 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 860 let work_dir = test_env.work_dir("repo"); 861 862 work_dir 863 .run_jj(["describe", "-m", "original message"]) 864 .success(); 865 866 std::fs::write(edit_script, ["dump editor"].join("\0")).unwrap(); 867 let output = work_dir.run_jj(["describe", "-m", "new message", "--edit"]); 868 insta::assert_snapshot!(output, @r" 869 ------- stderr ------- 870 Working copy (@) now at: qpvuntsm de694560 (empty) new message 871 Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) 872 [EOF] 873 "); 874 insta::assert_snapshot!( 875 std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r#" 876 new message 877 878 JJ: Lines starting with "JJ:" (like this one) will be removed. 879 "#); 880} 881 882#[test] 883fn test_edit_cannot_be_used_with_no_edit() { 884 let test_env = TestEnvironment::default(); 885 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 886 let work_dir = test_env.work_dir("repo"); 887 888 let output = work_dir.run_jj(["describe", "--no-edit", "--edit"]); 889 insta::assert_snapshot!(output, @r" 890 ------- stderr ------- 891 error: the argument '--no-edit' cannot be used with '--edit' 892 893 Usage: jj describe --no-edit [REVSETS]... 894 895 For more information, try '--help'. 896 [EOF] 897 [exit status: 2] 898 "); 899} 900 901#[must_use] 902fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { 903 let template = r#"commit_id.short() ++ " " ++ description"#; 904 work_dir.run_jj(["log", "-T", template]) 905}