release-plz 0.3.157

Update version and changelog based on semantic versioning and conventional commits
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
use release_plz_core::fs_utils::Utf8TempDir;

use crate::helpers::{
    package::{PackageType, TestPackage},
    test_context::TestContext,
    today,
};

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_default_tag_name() {
    let context = TestContext::new().await;

    // Configure git_only (tag name defaults to "v{version}")
    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    context.run_release_pr().success();

    // Verify PR was created with correct version bump (0.1.0 -> 0.1.1)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_custom_tag_name() {
    let context = TestContext::new().await;

    // Configure with a custom tag name template
    let config = r#"
[workspace]
git_only = true
git_tag_name = "release-{{ version }}-prod"
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context
        .repo
        .tag("release-0.1.0-prod", "Release 0.1.0 production")
        .unwrap();

    // Make a feature commit
    let new_file = context.repo_dir().join("src").join("new.rs");
    fs_err::write(&new_file, "// New feature").unwrap();
    context.push_all_changes("feat: add new module");

    // Run release-pr
    context.run_release_pr().success();

    // Verify PR was created
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    // The PR title uses the standard format, not the tag format
    // feat commits do patch bump in 0.x without features_always_increment_minor
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_finds_highest_version_tag() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create tags with corresponding Cargo.toml versions
    // In git_only mode, tags should point to commits where Cargo.toml version matches the tag
    use cargo_metadata::semver::Version;

    // Tag v0.1.0 (Cargo.toml already has 0.1.0 from cargo init)
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Update to 0.1.5, commit, and tag
    context.set_package_version(&context.gitea.repo, &Version::parse("0.1.5").unwrap());
    context.push_all_changes("chore: bump version to 0.1.5");
    context.repo.tag("v0.1.5", "Release v0.1.5").unwrap();

    // Update to 0.2.0, commit, and tag
    context.set_package_version(&context.gitea.repo, &Version::parse("0.2.0").unwrap());
    context.push_all_changes("chore: bump version to 0.2.0");
    context.repo.tag("v0.2.0", "Release v0.2.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    context.run_release_pr().success();

    // Verify it uses v0.2.0 as base (highest), bumps to v0.2.1
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.2.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_ignores_non_matching_tags() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create tags with different patterns
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();
    context.repo.tag("release-0.2.0", "Release 0.2.0").unwrap();
    context.repo.tag("beta-0.3.0", "Beta 0.3.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    context.run_release_pr().success();

    // Verify it only considers v0.1.0 (matching pattern)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_no_matching_tag_creates_initial_release() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create tag that doesn't match the default "v" pattern
    context.repo.tag("release-0.1.0", "Release 0.1.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    let _outcome = context.run_release_pr().success();

    // Verify PR was created for initial release
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(
        opened_prs.len(),
        1,
        "Expected PR for initial release when no matching tag exists"
    );

    // Verify it's a release PR with a version
    let pr = &opened_prs[0];
    assert_eq!(pr.title, "chore: release v0.1.0");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_no_tags_creates_initial_release() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Don't create any tags

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    let _outcome = context.run_release_pr().success();

    // Verify PR was created for initial release
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(
        opened_prs.len(),
        1,
        "Expected PR for initial release when no tags exist"
    );

    // Verify it's a release PR with a version
    let pr = &opened_prs[0];
    assert_eq!(pr.title, "chore: release v0.1.0");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_feat_commit_minor_bump() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
features_always_increment_minor = true
"#;
    context.write_release_plz_toml(config);

    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    let readme = context.repo_dir().join("README.md");

    // Make a fix commit
    fs_err::write(&readme, "# Fix 1").unwrap();
    context.push_all_changes("fix: first fix");

    // Make a feature commit
    let new_file = context.repo_dir().join("src").join("feature.rs");
    fs_err::write(&new_file, "// New feature").unwrap();
    context.push_all_changes("feat: add new feature");

    context.run_release_pr().success();

    // Verify minor bump (0.1.0 -> 0.2.0)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.2.0");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_respects_release_commits_regex() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
release_commits = "^feat:"
"#;
    context.write_release_plz_toml(config);

    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a fix commit (doesn't match regex)
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Fixed README").unwrap();
    context.push_all_changes("fix: correct readme");

    // Run release-pr - should not create PR
    let outcome = context.run_release_pr().success();
    outcome.stdout("{\"prs\":[]}\n");
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 0);

    // Now make a feature commit (matches regex)
    let new_file = context.repo_dir().join("src").join("feature.rs");
    fs_err::write(&new_file, "// New feature").unwrap();
    context.push_all_changes("feat: add new feature");

    // Run release-pr - should create PR
    context.run_release_pr().success();
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
}

// ============================================================================
// Workspace vs Package-Level Config
// ============================================================================

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_workspace_level_applies_to_all() {
    let context = TestContext::new_workspace(&["lib1", "lib2"]).await;

    // In workspace git_only mode, each package needs a unique tag pattern to distinguish tags
    // Using {{ package }} variable which will be replaced with the package name
    let config = r#"
[workspace]
git_only = true
git_tag_name = "{{ package }}-v{{ version }}"
"#;
    context.write_release_plz_toml(config);

    // Create tags for each package with their unique prefixes
    context
        .repo
        .tag("lib1-v0.1.0", "Release lib1 v0.1.0")
        .unwrap();
    context
        .repo
        .tag("lib2-v0.1.0", "Release lib2 v0.1.0")
        .unwrap();

    // Make changes to one package (workspace members are bins by default, so modify main.rs)
    let lib1_file = context.package_path("lib1").join("src").join("main.rs");
    fs_err::write(&lib1_file, "fn main() { println!(\"updated\"); }").unwrap();
    context.push_all_changes("feat: update lib1");

    context.run_release_pr().success();

    // Only lib1 should be in the release (it's the only one that changed)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    let pr_body = opened_prs[0].body.as_ref().unwrap();

    let today = today();
    let username = context.gitea.user.username();
    let repo = &context.gitea.repo;
    assert_eq!(
        format!(
            r"
## 🤖 New release

* `lib1`: 0.1.0 -> 0.1.1

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.1.1](https://localhost/{username}/{repo}/compare/lib1-v0.1.0...lib1-v0.1.1) - {today}

### Added

- update lib1
</blockquote>


</p></details>

---
This PR was generated with [release-plz](https://github.com/release-plz/release-plz/)."
        )
        .trim(),
        pr_body.trim()
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_per_package_prefix() {
    let context = TestContext::new_workspace(&["api", "core"]).await;

    // Workspace level: git_only with default template "{{ package }}-v{{ version }}"
    // Package "api": override with custom template "api-v{{ version }}"
    let config = r#"
[workspace]
git_only = true

[[package]]
name = "api"
git_tag_name = "api-v{{ version }}"
"#;
    context.write_release_plz_toml(config);

    // Tag the initial state (Cargo.toml already has 0.1.0)
    // In a workspace, each package needs its own tag with its configured template
    // api has custom template "api-v{{ version }}", core inherits workspace default "{{ package }}-v{{ version }}"
    context
        .repo
        .tag("api-v0.1.0", "Release api v0.1.0")
        .unwrap();
    context
        .repo
        .tag("core-v0.1.0", "Release core v0.1.0")
        .unwrap();

    // Make changes to api package
    let api_file = context.package_path("api").join("src").join("lib.rs");
    fs_err::write(&api_file, "pub fn api_updated() {}").unwrap();
    context.push_all_changes("feat: update api");

    context.run_release_pr().success();

    // Verify PR is created with correct content
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);

    let pr_body = opened_prs[0].body.as_ref().expect("PR should have body");

    let today = today();
    let username = context.gitea.user.username();
    let repo = &context.gitea.repo;
    assert_eq!(
        format!(
            r"
## 🤖 New release

* `api`: 0.1.0 -> 0.1.1 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.1.1](https://localhost/{username}/{repo}/compare/api-v0.1.0...api-v0.1.1) - {today}

### Added

- update api
</blockquote>


</p></details>

---
This PR was generated with [release-plz](https://github.com/release-plz/release-plz/)."
        )
        .trim(),
        pr_body.trim()
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_lightweight_tags() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag_lightweight("v0.1.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    context.run_release_pr().success();

    // Verify PR was created with correct version bump (0.1.0 -> 0.1.1)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_mixed_annotated_and_lightweight_tags() {
    use cargo_metadata::semver::Version;

    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create mix of tags with proper version updates
    // Tag v0.1.0 (Cargo.toml already has 0.1.0 from cargo init)
    context.repo.tag_lightweight("v0.1.0").unwrap();

    // Update to 0.1.5, commit, and tag as annotated
    context.set_package_version(&context.gitea.repo, &Version::parse("0.1.5").unwrap());
    context.push_all_changes("chore: bump version to 0.1.5");
    context.repo.tag("v0.1.5", "Release v0.1.5").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr
    context.run_release_pr().success();

    // Should use v0.1.5 (highest version) and bump to v0.1.6
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.6");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_invalid_tag_format() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create tags with invalid semver formats
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();
    context.repo.tag("v1.2.invalid", "Invalid version").unwrap();
    context.repo.tag("vNOT_A_VERSION", "Not a version").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr - should succeed using v0.1.0 and ignoring invalid tags
    context.run_release_pr().success();

    // Should use v0.1.0 (only valid tag) and bump to v0.1.1
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_breaking_change() {
    let context = TestContext::new().await;

    let config = r#"
[workspace]
git_only = true
features_always_increment_minor = true
"#;
    context.write_release_plz_toml(config);

    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a breaking change commit (using ! syntax)
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Breaking change").unwrap();
    context.push_all_changes("feat!: breaking API change");

    // Run release-pr
    context.run_release_pr().success();

    // Breaking change in 0.x should trigger minor bump (0.1.0 -> 0.2.0)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.2.0");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_multiple_packages_changed_workspace() {
    let context = TestContext::new_workspace(&["pkg1", "pkg2", "pkg3"]).await;

    // Use workspace-level template with {{ package }} variable for all packages
    let config = r#"
[workspace]
git_only = true
git_tag_name = "{{ package }}-v{{ version }}"
"#;
    context.write_release_plz_toml(config);

    // Create tags for all packages
    context
        .repo
        .tag("pkg1-v0.1.0", "Release pkg1 v0.1.0")
        .unwrap();
    context
        .repo
        .tag("pkg2-v0.1.0", "Release pkg2 v0.1.0")
        .unwrap();
    context
        .repo
        .tag("pkg3-v0.1.0", "Release pkg3 v0.1.0")
        .unwrap();

    // Make changes to multiple packages
    let pkg1_file = context.package_path("pkg1").join("src").join("main.rs");
    fs_err::write(&pkg1_file, "fn main() { println!(\"pkg1 updated\"); }").unwrap();

    let pkg2_file = context.package_path("pkg2").join("src").join("main.rs");
    fs_err::write(&pkg2_file, "fn main() { println!(\"pkg2 updated\"); }").unwrap();

    context.push_all_changes("feat: update pkg1 and pkg2");

    // Run release-pr
    context.run_release_pr().success();

    // Should create single PR with both changed packages
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);

    let today = today();
    let username = context.gitea.user.username();
    let repo = &context.gitea.repo;
    let pr_body = opened_prs[0].body.as_ref().unwrap();
    assert_eq!(
        format!(
            "
## 🤖 New release

* `pkg1`: 0.1.0 -> 0.1.1
* `pkg2`: 0.1.0 -> 0.1.1

<details><summary><i><b>Changelog</b></i></summary><p>

## `pkg1`

<blockquote>

## [0.1.1](https://localhost/{username}/{repo}/compare/pkg1-v0.1.0...pkg1-v0.1.1) - {today}

### Added

- update pkg1 and pkg2
</blockquote>

## `pkg2`

<blockquote>

## [0.1.1](https://localhost/{username}/{repo}/compare/pkg2-v0.1.0...pkg2-v0.1.1) - {today}

### Added

- update pkg1 and pkg2
</blockquote>


</p></details>

---
This PR was generated with [release-plz](https://github.com/release-plz/release-plz/)."
        )
        .trim(),
        pr_body.trim()
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_publish_enabled_fails_validation() {
    let context = TestContext::new().await;

    // Configure with both git_only = true and publish not disabled
    // This should fail validation because they are mutually exclusive
    let config = r#"
[workspace]
git_only = true
publish = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr should fail due to validation error
    let error = context.run_release_pr().failure().to_string();
    assert!(
        error.contains("git_only")
            && error.contains("publish")
            && error.contains("mutually exclusive"),
        "Expected validation error about git_only and publish being mutually exclusive, got: {error}"
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_publish_disabled_succeeds() {
    let context = TestContext::new().await;

    // Configure with git_only = true and publish = false - this is valid
    let config = r#"
[workspace]
git_only = true
publish = false
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr should succeed
    context.run_release_pr().success();

    // Verify PR was created
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_workspace_with_package_publish_enabled_fails() {
    let context = TestContext::new_workspace(&["pkg-a", "pkg-b"]).await;

    // Workspace has git_only = true, but pkg-a has publish = true
    // This should fail validation
    let config = r#"
[workspace]
git_only = true

[[package]]
name = "pkg-a"
publish = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tags
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a commit to pkg-a
    let readme = context.package_path("pkg-a").join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update pkg-a readme");

    // Run release-pr should fail due to validation error
    let error = context.run_release_pr().failure().to_string();
    assert!(
        error.contains("git_only")
            && error.contains("publish")
            && error.contains("mutually exclusive"),
        "Expected validation error about git_only and publish being mutually exclusive, got: {error}",
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_with_publish_enabled_fails_validation_release_cmd() {
    let context = TestContext::new().await;

    // Configure with both git_only = true and publish = true
    // This should fail validation because they are mutually exclusive
    let config = r#"
[workspace]
git_only = true
publish = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release command should fail due to validation error
    let error = context.run_release().failure().to_string();
    assert!(
        error.contains("git_only")
            && error.contains("publish")
            && error.contains("mutually exclusive"),
        "Expected validation error about git_only and publish being mutually exclusive, got: {error}"
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_release_creates_tag() {
    use cargo_metadata::semver::Version;

    let context = TestContext::new().await;

    // Configure with git_only = true and publish = false
    let config = r#"
[workspace]
git_only = true
publish = false
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag and update Cargo.toml to match
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Update version and make a new commit
    context.set_package_version(&context.gitea.repo, &Version::parse("0.1.1").unwrap());
    context.run_cargo_check();
    context.push_all_changes("fix: bug fix");

    let crate_name = &context.gitea.repo;
    let expected_tag = "v0.1.1";

    // Verify tag doesn't exist yet
    let is_tag_created = || {
        context.repo.git(&["fetch", "--tags"]).unwrap();
        context.repo.tag_exists(expected_tag).unwrap()
    };
    assert!(!is_tag_created(), "Tag should not exist before release");

    // Run release command
    let outcome = context.run_release().success();

    // Verify JSON output shows the release
    let expected_stdout = serde_json::json!({
        "releases": [
            {
                "package_name": crate_name,
                "prs": [],
                "tag": expected_tag,
                "version": "0.1.1",
            }
        ]
    })
    .to_string();
    outcome.stdout(format!("{expected_stdout}\n"));

    // Verify the tag was created
    assert!(is_tag_created(), "Tag should exist after release");

    // Verify no packages were published (since publish = false)
    let dest_dir = Utf8TempDir::new().unwrap();
    let packages = context.download_package(dest_dir.path());
    assert!(packages.is_empty());
}

/// Test for <https://github.com/release-plz/release-plz/issues/2594>
/// In `git_only` mode, release-plz should NOT check the cargo registry for existing packages.
/// This test verifies that a package with a name that exists on the cargo registry
/// still gets tagged in `git_only` mode, because the registry is not checked.
#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_release_does_not_check_crates_io() {
    use cargo_metadata::semver::Version;

    // Create workspace with two packages
    let context = TestContext::new_workspace(&["mylib", "mybin"]).await;

    // Publish "mylib" to the cargo registry.
    context.run_cargo_publish("mylib");

    // Configure with git_only = true and publish = false
    let config = r#"
[workspace]
git_only = true
publish = false
"#;
    context.write_release_plz_toml(config);

    // Create initial release tags
    context
        .repo
        .tag("mylib-v0.1.0", "Release mylib v0.1.0")
        .unwrap();
    context
        .repo
        .tag("mybin-v0.1.0", "Release mybin v0.1.0")
        .unwrap();

    // Update versions and make a new commit
    context.set_package_version("mylib", &Version::parse("0.1.1").unwrap());
    context.set_package_version("mybin", &Version::parse("0.1.1").unwrap());
    context.run_cargo_check();
    context.push_all_changes("fix: bug fix in both packages");

    // Publish the new version of "mylib" to the cargo registry as well.
    context.run_cargo_publish("mylib");

    let expected_mylib_tag = "mylib-v0.1.1";
    let expected_mybin_tag = "mybin-v0.1.1";

    // Verify tags don't exist yet
    let tag_exists = |tag: &str| {
        context.repo.git(&["fetch", "--tags"]).unwrap();
        context.repo.tag_exists(tag).unwrap()
    };
    assert!(
        !tag_exists(expected_mylib_tag),
        "mylib tag should not exist before release"
    );
    assert!(
        !tag_exists(expected_mybin_tag),
        "mybin tag should not exist before release"
    );

    // Run release command - this should succeed and create both tags
    // Without the fix, it would only create mybin tag because "mylib" exists on the cargo registry
    let outcome = context.run_release().success();

    // Verify JSON output shows both releases
    let expected_stdout = serde_json::json!({
        "releases": [
            {
                "package_name": "mylib",
                "prs": [],
                "tag": expected_mylib_tag,
                "version": "0.1.1",
            },
            {
                "package_name": "mybin",
                "prs": [],
                "tag": expected_mybin_tag,
                "version": "0.1.1",
            }
        ]
    })
    .to_string();
    outcome.stdout(format!("{expected_stdout}\n"));

    // Verify BOTH tags were created.
    assert!(
        tag_exists(expected_mylib_tag),
        "mylib tag should exist after release (git_only should not check the cargo registry)"
    );
    assert!(
        tag_exists(expected_mybin_tag),
        "mybin tag should exist after release"
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_update_handles_workspace_path_dependencies() {
    let context = TestContext::new_workspace_with_packages(&[
        TestPackage::new("mylib").with_type(PackageType::Lib),
        TestPackage::new("mybin")
            .with_type(PackageType::Bin)
            .with_path_dependencies(vec!["../mylib"]),
    ])
    .await;

    let config = r#"
[workspace]
git_only = true
publish = false
"#;
    context.write_release_plz_toml(config);

    context
        .repo
        .tag("mylib-v0.1.0", "Release mylib v0.1.0")
        .unwrap();
    context
        .repo
        .tag("mybin-v0.1.0", "Release mybin v0.1.0")
        .unwrap();

    let readme = context.package_path("mybin").join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update mybin readme");

    context.run_release_pr().success();

    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);

    let pr_body = opened_prs[0].body.as_ref().expect("PR should have body");

    let today = today();
    let username = context.gitea.user.username();
    let repo = &context.gitea.repo;
    assert_eq!(
        format!(
            r"
## 🤖 New release

* `mybin`: 0.1.0 -> 0.1.1

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.1.1](https://localhost/{username}/{repo}/compare/mybin-v0.1.0...mybin-v0.1.1) - {today}

### Fixed

- update mybin readme
</blockquote>


</p></details>

---
This PR was generated with [release-plz](https://github.com/release-plz/release-plz/)."
        )
        .trim(),
        pr_body.trim()
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_update_handles_root_package_path_dependencies() {
    use cargo_utils::{CARGO_TOML, LocalManifest};

    let context = TestContext::new().await;

    // Workspace layout for this scenario:
    // - `.` is package `mybin` (root package, binary)
    // - `crates/mylib` is package `mylib` (workspace member, library)
    // - `mybin` depends on `mylib` via `path = "crates/mylib"`
    // Convert root package to `mybin` and add a workspace member at `crates/mylib`.
    let root_manifest_path = context.repo_dir().join(CARGO_TOML);
    let mut root_manifest = LocalManifest::try_new(&root_manifest_path).unwrap();
    root_manifest.data["package"]["name"] = "mybin".into();
    root_manifest.data["workspace"]["resolver"] = "3".into();
    let mut members = toml_edit::Array::new();
    members.push(".");
    members.push("crates/mylib");
    root_manifest.data["workspace"]["members"] = toml_edit::Item::Value(members.into());
    root_manifest.write().unwrap();

    let mylib_dir = context.repo_dir().join("crates").join("mylib");
    fs_err::create_dir_all(&mylib_dir).unwrap();
    TestPackage::new("mylib")
        .with_type(PackageType::Lib)
        .cargo_init(&mylib_dir);

    assert_cmd::Command::new("cargo")
        .current_dir(context.repo_dir())
        .args(["add", "--path", "crates/mylib"])
        .assert()
        .success();

    context.run_cargo_check();
    context.push_all_changes("chore: setup root mybin with crates/mylib path dependency");

    let config = r#"
[workspace]
git_only = true
publish = false
"#;
    context.write_release_plz_toml(config);

    context
        .repo
        .tag("mylib-v0.1.0", "Release mylib v0.1.0")
        .unwrap();
    context
        .repo
        .tag("mybin-v0.1.0", "Release mybin v0.1.0")
        .unwrap();

    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update mybin readme");

    context.run_release_pr().success();

    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore(mybin): release v0.1.1");

    let pr_body = opened_prs[0].body.as_ref().expect("PR should have body");
    assert!(
        pr_body.contains("`mybin`: 0.1.0 -> 0.1.1"),
        "PR body should include mybin release entry"
    );
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn git_only_processes_packages_with_publish_false_in_manifest() {
    use cargo_utils::LocalManifest;

    let context = TestContext::new().await;

    // Set publish = false in the Cargo.toml manifest
    let cargo_toml_path = context.repo_dir().join("Cargo.toml");
    let mut cargo_toml = LocalManifest::try_new(&cargo_toml_path).unwrap();
    cargo_toml.data["package"]["publish"] = false.into();
    cargo_toml.write().unwrap();
    context.push_all_changes("chore: set publish = false");

    // Configure git_only = true in release-plz config
    let config = r#"
[workspace]
git_only = true
"#;
    context.write_release_plz_toml(config);

    // Create initial release tag
    context.repo.tag("v0.1.0", "Release v0.1.0").unwrap();

    // Make a fix commit
    let readme = context.repo_dir().join("README.md");
    fs_err::write(&readme, "# Updated README").unwrap();
    context.push_all_changes("fix: update readme");

    // Run release-pr - should succeed even though publish = false in manifest
    context.run_release_pr().success();

    // Verify PR was created with correct version bump (0.1.0 -> 0.1.1)
    let opened_prs = context.opened_release_prs().await;
    assert_eq!(opened_prs.len(), 1);
    assert_eq!(opened_prs[0].title, "chore: release v0.1.1");
}