git-worktree-manager 0.0.39

CLI tool integrating git worktree with AI coding assistants
Documentation
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
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
/// Integration tests for core operations — ported from Python test_core.py.
/// Covers: create_worktree, finish/merge, delete, sync, clean, change-base,
/// list, status, resume, and remote-branch scenarios.
mod common;

use common::TestRepo;

// ---------------------------------------------------------------------------
// Helper: run git at a worktree path
// ---------------------------------------------------------------------------

fn worktree_path(repo: &TestRepo, branch: &str) -> std::path::PathBuf {
    repo.path().parent().unwrap().join(format!(
        "{}-{}",
        repo.path().file_name().unwrap().to_str().unwrap(),
        branch,
    ))
}

// ===========================================================================
// create_worktree — basic
// ===========================================================================

#[test]
fn test_create_worktree_basic() {
    let repo = TestRepo::new();
    let output = repo.cw(&["new", "fix-auth", "--no-term"]);
    assert!(
        output.status.success(),
        "cw new failed: {}",
        String::from_utf8_lossy(&output.stdout)
    );

    let wt = worktree_path(&repo, "fix-auth");
    assert!(wt.exists());
    assert!(wt.join("README.md").exists());

    // Branch exists
    let branches = repo.git_stdout(&["branch", "--list", "fix-auth"]);
    assert!(branches.contains("fix-auth"));

    // Worktree registered
    let wt_list = repo.git_stdout(&["worktree", "list"]);
    assert!(wt_list.contains("fix-auth"));
}

// ===========================================================================
// create_worktree — custom path
// ===========================================================================

#[test]
fn test_create_worktree_custom_path() {
    let mut repo = TestRepo::new();
    let custom = repo.custom_path("my_custom_path");
    let output = repo.cw(&[
        "new",
        "custom-branch",
        "--no-term",
        "--path",
        custom.to_str().unwrap(),
    ]);
    assert!(
        output.status.success(),
        "cw new --path failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    assert!(custom.exists());
}

// ===========================================================================
// create_worktree — with base branch
// ===========================================================================

#[test]
fn test_create_worktree_with_base_branch() {
    let repo = TestRepo::new();
    repo.create_branch("develop");

    let output = repo.cw(&["new", "feature", "--no-term", "--base", "develop"]);
    assert!(output.status.success());

    let wt = worktree_path(&repo, "feature");
    let log = TestRepo::git_stdout_at(&wt, &["log", "--oneline", "-1"]);
    assert!(log.contains("Initial commit"));
}

// ===========================================================================
// create_worktree — invalid base branch
// ===========================================================================

#[test]
fn test_create_worktree_invalid_base() {
    let repo = TestRepo::new();
    let output = repo.cw(&[
        "new",
        "feature",
        "--no-term",
        "--base",
        "nonexistent-branch",
    ]);
    assert!(!output.status.success());
    let combined = format!(
        "{}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    assert!(
        combined.contains("not found")
            || combined.contains("does not exist")
            || combined.contains("error"),
        "Expected error about missing branch, got: {}",
        combined
    );
}

// ===========================================================================
// create_worktree — invalid branch names
// ===========================================================================

#[test]
fn test_create_worktree_invalid_branch_name() {
    let repo = TestRepo::new();
    let invalid_names = [
        "bad..name",
        "/feature",
        "feature/",
        "feat//test",
        "feat~test",
        "feat^test",
        "feat test",
    ];
    for name in &invalid_names {
        let output = repo.cw(&["new", name, "--no-term"]);
        assert!(
            !output.status.success(),
            "Expected failure for branch name '{}', but got success",
            name,
        );
    }
}

// ===========================================================================
// create_worktree — existing worktree (duplicate)
// ===========================================================================

#[test]
fn test_create_worktree_existing_worktree() {
    let repo = TestRepo::new();
    let output1 = repo.cw(&["new", "duplicate-test", "--no-term"]);
    assert!(output1.status.success());

    // Second creation with same name should fail
    let output2 = repo.cw(&["new", "duplicate-test", "--no-term"]);
    assert!(!output2.status.success());
    let combined = format!(
        "{}{}",
        String::from_utf8_lossy(&output2.stdout),
        String::from_utf8_lossy(&output2.stderr),
    );
    assert!(
        combined.contains("already exists")
            || combined.contains("already")
            || combined.contains("error"),
        "Expected 'already exists' error, got: {}",
        combined
    );
}

// ===========================================================================
// create_worktree — existing local branch (no worktree yet)
// ===========================================================================

#[test]
fn test_create_worktree_existing_branch() {
    let repo = TestRepo::new();
    repo.create_branch("existing-branch");

    // Create worktree from existing branch
    let output = repo.cw(&["new", "existing-branch", "--no-term"]);
    assert!(
        output.status.success(),
        "cw new for existing branch failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    let wt = worktree_path(&repo, "existing-branch");
    assert!(wt.exists());
}

// ===========================================================================
// create_worktree — remote-only branch
// ===========================================================================

#[test]
fn test_create_worktree_from_remote_only_branch() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    // Create branch, push, delete local
    repo.create_branch("remote-feature");
    repo.git(&["push", "origin", "remote-feature"]);
    repo.git(&["branch", "-D", "remote-feature"]);

    // Verify not local
    let branches = repo.git_stdout(&["branch", "--list", "remote-feature"]);
    assert!(!branches.contains("remote-feature"));

    // Create worktree from remote branch
    let output = repo.cw(&["new", "remote-feature", "--no-term"]);
    assert!(
        output.status.success(),
        "cw new from remote branch failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    let wt = worktree_path(&repo, "remote-feature");
    assert!(wt.exists());
}

// ===========================================================================
// create_worktree — remote branch with custom path
// ===========================================================================

#[test]
fn test_create_worktree_from_remote_with_custom_path() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    repo.create_branch("remote-custom-path");
    repo.git(&["push", "origin", "remote-custom-path"]);
    repo.git(&["branch", "-D", "remote-custom-path"]);

    let custom = repo.custom_path("my-custom-remote-worktree");
    let output = repo.cw(&[
        "new",
        "remote-custom-path",
        "--no-term",
        "--path",
        custom.to_str().unwrap(),
    ]);
    assert!(output.status.success());
    assert!(custom.exists());
    assert!(custom.join("README.md").exists());
}

// ===========================================================================
// create_worktree — remote branch with different content
// ===========================================================================

#[test]
fn test_create_worktree_remote_has_different_content() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    // Create branch with unique content
    repo.git(&["checkout", "-b", "content-branch"]);
    std::fs::write(repo.path().join("remote-file.txt"), "remote content").unwrap();
    repo.git(&["add", "."]);
    repo.git(&["commit", "-m", "Add remote file"]);
    repo.git(&["push", "origin", "content-branch"]);

    // Switch back and delete local
    repo.git(&["checkout", "main"]);
    repo.git(&["branch", "-D", "content-branch"]);

    assert!(!repo.path().join("remote-file.txt").exists());

    let output = repo.cw(&["new", "content-branch", "--no-term"]);
    assert!(output.status.success());

    let wt = worktree_path(&repo, "content-branch");
    assert!(wt.join("remote-file.txt").exists());
    assert_eq!(
        std::fs::read_to_string(wt.join("remote-file.txt")).unwrap(),
        "remote content"
    );
}

// ===========================================================================
// create_worktree — remote with explicit base
// ===========================================================================

#[test]
fn test_create_worktree_from_remote_with_explicit_base() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();
    repo.create_branch("develop");

    repo.create_branch("remote-with-base");
    repo.git(&["push", "origin", "remote-with-base"]);
    repo.git(&["branch", "-D", "remote-with-base"]);

    let output = repo.cw(&["new", "remote-with-base", "--no-term", "--base", "develop"]);
    assert!(output.status.success());

    let wt = worktree_path(&repo, "remote-with-base");
    assert!(wt.exists());
}

// ===========================================================================
// create_worktree — remote with invalid base
// ===========================================================================

#[test]
fn test_create_worktree_from_remote_with_invalid_base() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    repo.create_branch("remote-invalid-base");
    repo.git(&["push", "origin", "remote-invalid-base"]);
    repo.git(&["branch", "-D", "remote-invalid-base"]);

    let output = repo.cw(&[
        "new",
        "remote-invalid-base",
        "--no-term",
        "--base",
        "nonexistent-base",
    ]);
    assert!(!output.status.success());
}

// ===========================================================================
// create_worktree — local takes precedence over remote
// ===========================================================================

#[test]
fn test_create_worktree_local_branch_takes_precedence_over_remote() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    repo.create_branch("both-local-remote");
    repo.git(&["push", "origin", "both-local-remote"]);
    repo.git(&["fetch", "origin"]);

    // Branch exists both locally and remotely — should use local
    let output = repo.cw(&["new", "both-local-remote", "--no-term"]);
    assert!(output.status.success());
    let wt = worktree_path(&repo, "both-local-remote");
    assert!(wt.exists());
}

// ===========================================================================
// finish/merge — success
// ===========================================================================

#[test]
fn test_finish_worktree_success() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("finish-test");

    // Commit in worktree
    TestRepo::commit_file_at(&wt, "test.txt", "test content", "Add test file");

    // Merge from worktree directory
    let output = TestRepo::cw_at(&wt, &["merge"]);
    assert!(
        output.status.success(),
        "merge failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    // Worktree removed
    assert!(!wt.exists());

    // Branch deleted
    let branches = repo.git_stdout(&["branch", "--list", "finish-test"]);
    assert!(!branches.contains("finish-test"));

    // Changes merged to main
    assert!(repo.path().join("test.txt").exists());
    assert_eq!(
        std::fs::read_to_string(repo.path().join("test.txt")).unwrap(),
        "test content"
    );
}

// ===========================================================================
// finish/merge — with rebase
// ===========================================================================

#[test]
fn test_finish_worktree_with_rebase() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("rebase-test");

    // Commit in worktree
    TestRepo::commit_file_at(&wt, "feature.txt", "feature", "Add feature");

    // Commit in main (simulating other work)
    repo.commit_file("main.txt", "main work", "Work on main");

    // Merge from worktree
    let output = TestRepo::cw_at(&wt, &["merge"]);
    assert!(output.status.success());

    // Both files should exist in main
    assert!(repo.path().join("feature.txt").exists());
    assert!(repo.path().join("main.txt").exists());
}

// ===========================================================================
// finish/merge — dry run
// ===========================================================================

#[test]
fn test_finish_worktree_dry_run() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("dry-run-test");

    TestRepo::commit_file_at(&wt, "feature.txt", "feature content", "Add feature");

    let output = TestRepo::cw_at(&wt, &["merge", "--dry-run"]);
    assert!(output.status.success());

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("DRY RUN")
            || stdout.contains("dry run")
            || stdout.contains("Dry run")
            || stdout.contains("Would"),
        "Expected dry-run indicator in output, got: {}",
        stdout
    );

    // Nothing should have changed
    assert!(wt.exists());
    assert!(wt.join("feature.txt").exists());

    // Branch should still exist
    let branches = repo.git_stdout(&["branch", "--list", "dry-run-test"]);
    assert!(branches.contains("dry-run-test"));

    // Changes should NOT be in main
    assert!(!repo.path().join("feature.txt").exists());
}

// ===========================================================================
// merge — success (alias for finish)
// ===========================================================================

#[test]
fn test_merge_worktree_success() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("merge-test");

    TestRepo::commit_file_at(&wt, "merge.txt", "merge content", "Add merge file");

    let output = TestRepo::cw_at(&wt, &["merge"]);
    assert!(output.status.success());

    assert!(!wt.exists());

    let branches = repo.git_stdout(&["branch", "--list", "merge-test"]);
    assert!(!branches.contains("merge-test"));

    assert!(repo.path().join("merge.txt").exists());
    assert_eq!(
        std::fs::read_to_string(repo.path().join("merge.txt")).unwrap(),
        "merge content"
    );
}

// ===========================================================================
// merge — with rebase
// ===========================================================================

#[test]
fn test_merge_worktree_with_rebase() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("merge-rebase-test");

    TestRepo::commit_file_at(&wt, "feature.txt", "feature", "Add feature");
    repo.commit_file("main.txt", "main work", "Work on main");

    let output = TestRepo::cw_at(&wt, &["merge"]);
    assert!(output.status.success());

    assert!(repo.path().join("feature.txt").exists());
    assert!(repo.path().join("main.txt").exists());
}

// ===========================================================================
// merge — dry run
// ===========================================================================

#[test]
fn test_merge_worktree_dry_run() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("merge-dry-run-test");

    TestRepo::commit_file_at(&wt, "feature.txt", "feature content", "Add feature");

    let output = TestRepo::cw_at(&wt, &["merge", "--dry-run"]);
    assert!(output.status.success());

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("DRY RUN")
            || stdout.contains("dry run")
            || stdout.contains("Dry run")
            || stdout.contains("Would"),
    );

    assert!(wt.exists());

    let branches = repo.git_stdout(&["branch", "--list", "merge-dry-run-test"]);
    assert!(branches.contains("merge-dry-run-test"));

    assert!(!repo.path().join("feature.txt").exists());
}

// ===========================================================================
// delete — by branch name
// ===========================================================================

#[test]
fn test_delete_worktree_by_branch() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("delete-me");
    assert!(wt.exists());

    let output = repo.cw(&["delete", "delete-me"]);
    assert!(output.status.success());

    assert!(!wt.exists());

    let branches = repo.git_stdout(&["branch", "--list", "delete-me"]);
    assert!(!branches.contains("delete-me"));
}

// ===========================================================================
// delete — by path
// ===========================================================================

#[test]
fn test_delete_worktree_by_path() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("delete-by-path");

    let output = repo.cw(&["delete", wt.to_str().unwrap()]);
    assert!(output.status.success());
    assert!(!wt.exists());
}

// ===========================================================================
// delete — keep branch
// ===========================================================================

#[test]
fn test_delete_worktree_keep_branch() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("keep-branch");

    let output = repo.cw(&["delete", "keep-branch", "--keep-branch"]);
    assert!(output.status.success());

    assert!(!wt.exists());

    // Branch should still exist
    let branches = repo.git_stdout(&["branch", "--list", "keep-branch"]);
    assert!(branches.contains("keep-branch"));
}

// ===========================================================================
// delete — nonexistent
// ===========================================================================

#[test]
fn test_delete_worktree_nonexistent() {
    let repo = TestRepo::new();
    let output = repo.cw(&["delete", "nonexistent-branch"]);
    assert!(!output.status.success());
}

// ===========================================================================
// delete — main repo protection
// ===========================================================================

#[test]
fn test_delete_main_repo_protection() {
    let repo = TestRepo::new();
    let output = repo.cw(&["delete", repo.path().to_str().unwrap()]);
    assert!(!output.status.success());
    let combined = format!(
        "{}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    assert!(
        combined.contains("main")
            || combined.contains("cannot")
            || combined.contains("Cannot")
            || combined.contains("error"),
        "Expected protection error, got: {}",
        combined
    );
}

// ===========================================================================
// delete — remote-only branch worktree
// ===========================================================================

#[test]
fn test_delete_worktree_created_from_remote() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    repo.create_branch("delete-remote-test");
    repo.git(&["push", "origin", "delete-remote-test"]);
    repo.git(&["branch", "-D", "delete-remote-test"]);

    let output = repo.cw(&["new", "delete-remote-test", "--no-term"]);
    assert!(output.status.success());

    let wt = worktree_path(&repo, "delete-remote-test");
    assert!(wt.exists());

    let del = repo.cw(&["delete", "delete-remote-test"]);
    assert!(del.status.success());
    assert!(!wt.exists());
}

// ===========================================================================
// list
// ===========================================================================

#[test]
fn test_list_worktrees() {
    let repo = TestRepo::new();
    repo.create_worktree("wt1");
    repo.create_worktree("wt2");

    let stdout = repo.cw_stdout(&["list"]);
    assert!(stdout.contains("wt1"));
    assert!(stdout.contains("wt2"));
}

#[test]
fn test_list_in_repo() {
    let repo = TestRepo::new();
    let output = repo.cw(&["list"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Worktrees for repository:"));
}

// ===========================================================================
// status
// ===========================================================================

#[test]
fn test_status_in_repo() {
    let repo = TestRepo::new();
    let output = repo.cw(&["status"]);
    assert!(output.status.success());
}

#[test]
fn test_show_status_in_worktree() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("status-test");

    let stdout = TestRepo::cw_stdout_at(&wt, &["status"]);
    assert!(stdout.contains("status-test"));
}

#[test]
fn test_show_status_in_main_repo() {
    let repo = TestRepo::new();
    let output = repo.cw(&["status"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Worktree") || stdout.contains("worktree") || stdout.contains("main"));
}

// ===========================================================================
// sync — single worktree
// ===========================================================================

#[test]
fn test_sync_worktree_success() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("sync-success-test");

    TestRepo::commit_file_at(&wt, "sync-feature.txt", "feature content", "Add feature");
    repo.commit_file("main-work.txt", "main work", "Main work");

    let output = TestRepo::cw_at(&wt, &["sync"]);
    assert!(
        output.status.success(),
        "sync failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    // After sync (rebase), both files should be in worktree
    assert!(wt.join("sync-feature.txt").exists());
    assert!(wt.join("main-work.txt").exists());
}

// ===========================================================================
// sync — all worktrees
// ===========================================================================

#[test]
fn test_sync_all_worktrees() {
    let repo = TestRepo::new();
    let wt1 = repo.create_worktree("wt1");
    let wt2 = repo.create_worktree("wt2");

    TestRepo::commit_file_at(&wt1, "wt1-file.txt", "wt1 content", "wt1 work");
    TestRepo::commit_file_at(&wt2, "wt2-file.txt", "wt2 content", "wt2 work");
    repo.commit_file("main-work.txt", "main work", "Main work");

    let output = repo.cw(&["sync", "--all"]);
    assert!(
        output.status.success(),
        "sync --all failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    assert!(wt1.join("main-work.txt").exists());
    assert!(wt1.join("wt1-file.txt").exists());
    assert!(wt2.join("main-work.txt").exists());
    assert!(wt2.join("wt2-file.txt").exists());
}

// ===========================================================================
// sync — fetch only
// ===========================================================================

#[test]
fn test_sync_fetch_only() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("fetch-only-test");

    TestRepo::commit_file_at(&wt, "feature.txt", "feature", "Add feature");
    repo.commit_file("main-work.txt", "main work", "Main work");

    let output = TestRepo::cw_at(&wt, &["sync", "--fetch-only"]);
    assert!(output.status.success());

    // fetch-only should NOT rebase, so main-work.txt should not appear in worktree
    assert!(wt.join("feature.txt").exists());
    // main-work.txt should NOT be in the worktree since no rebase happened
    assert!(!wt.join("main-work.txt").exists());
}

// ===========================================================================
// sync — named branch
// ===========================================================================

#[test]
fn test_sync_named_branch() {
    let repo = TestRepo::new();
    let _wt = repo.create_worktree("sync-test");

    // Sync by branch name from main repo
    let output = repo.cw(&["sync", "sync-test"]);
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("Fetching")
            || stdout.contains("Syncing")
            || stdout.contains("Sync")
            || stdout.contains("sync")
            || stdout.contains("Rebase")
            || output.status.success(),
    );
}

// ===========================================================================
// sync — nested worktrees (topological sort)
// ===========================================================================

#[test]
fn test_sync_nested_worktrees() {
    let repo = TestRepo::new();
    let wt_a = repo.create_worktree("feature-a");

    TestRepo::commit_file_at(&wt_a, "feature-a.txt", "feature A", "Add feature A");

    // Create nested worktree from feature-a
    let output = repo.cw(&[
        "new",
        "feature-a-refinement",
        "--no-term",
        "--base",
        "feature-a",
    ]);
    assert!(output.status.success());
    let wt_a_ref = worktree_path(&repo, "feature-a-refinement");

    TestRepo::commit_file_at(&wt_a_ref, "refinement.txt", "refinement", "Add refinement");

    // Make a new commit in main
    repo.commit_file("main-update.txt", "main update", "Update main");

    // Sync all
    let output = repo.cw(&["sync", "--all"]);
    assert!(
        output.status.success(),
        "sync --all failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    // feature-a should have main's update
    assert!(wt_a.join("main-update.txt").exists());
    assert!(wt_a.join("feature-a.txt").exists());

    // feature-a-refinement should have both
    assert!(wt_a_ref.join("main-update.txt").exists());
    assert!(wt_a_ref.join("feature-a.txt").exists());
    assert!(wt_a_ref.join("refinement.txt").exists());
}

// ===========================================================================
// clean — no criteria
// ===========================================================================

#[test]
fn test_clean_no_criteria() {
    let repo = TestRepo::new();
    let _output = repo.cw(&["clean"]);
    let combined = repo.cw_combined(&["clean"]);
    assert!(
        combined.contains("criterion")
            || combined.contains("specify")
            || combined.contains("Specify")
            || combined.contains("error")
            || combined.contains("must"),
        "Expected error about missing criteria, got: {}",
        combined
    );
}

// ===========================================================================
// clean — merged (dry run)
// ===========================================================================

#[test]
fn test_clean_merged_dry_run() {
    let repo = TestRepo::new();
    let output = repo.cw(&["clean", "--merged", "--dry-run"]);
    assert!(output.status.success());
}

// ===========================================================================
// clean — merged
// ===========================================================================

#[test]
fn test_clean_merged() {
    let repo = TestRepo::new();
    let _wt = repo.create_worktree("clean-merged-test");

    let output = repo.cw(&["clean", "--merged"]);
    assert!(output.status.success());
}

// ===========================================================================
// clean — older than
// ===========================================================================

#[test]
fn test_clean_older_than_dry_run() {
    let repo = TestRepo::new();
    repo.create_worktree("old-wt");

    let output = repo.cw(&["clean", "--older-than", "0", "--dry-run"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    // --older-than 0 means "age >= 0 days" = all worktrees
    assert!(
        stdout.contains("old-wt")
            || stdout.contains("Would")
            || stdout.contains("would")
            || stdout.contains("dry"),
        "Expected worktree mention in dry-run output, got: {}",
        stdout
    );
}

// ===========================================================================
// change-base — success
// ===========================================================================

#[test]
fn test_change_base_branch_success() {
    let repo = TestRepo::new();
    repo.create_branch("master");

    let wt = repo.create_worktree("feature-test");
    TestRepo::commit_file_at(&wt, "feature.txt", "feature content", "Add feature");

    let output = TestRepo::cw_at(&wt, &["change-base", "master"]);
    assert!(
        output.status.success(),
        "change-base failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    // Verify metadata updated
    let meta = repo.git_stdout(&[
        "config",
        "--local",
        "--get",
        "branch.feature-test.worktreeBase",
    ]);
    assert!(
        meta.trim() == "master",
        "Expected 'master', got '{}'",
        meta.trim()
    );
}

// ===========================================================================
// change-base — with target
// ===========================================================================

#[test]
fn test_change_base_branch_with_target() {
    let repo = TestRepo::new();
    repo.create_branch("master");

    let wt = repo.create_worktree("target-test");
    TestRepo::commit_file_at(&wt, "file.txt", "content", "Add file");

    // Change base from main repo by specifying target branch
    let output = repo.cw(&["change-base", "master", "target-test"]);
    assert!(output.status.success());

    let meta = repo.git_stdout(&[
        "config",
        "--local",
        "--get",
        "branch.target-test.worktreeBase",
    ]);
    assert!(meta.trim() == "master");
}

// ===========================================================================
// change-base — dry run
// ===========================================================================

#[test]
fn test_change_base_branch_dry_run() {
    let repo = TestRepo::new();
    repo.create_branch("master");

    let wt = repo.create_worktree("dry-run-base");

    let output = TestRepo::cw_at(&wt, &["change-base", "master", "--dry-run"]);
    assert!(output.status.success());

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("DRY RUN")
            || stdout.contains("dry run")
            || stdout.contains("Dry run")
            || stdout.contains("Would"),
    );

    // Base branch should NOT have changed
    let meta = repo.git_stdout(&[
        "config",
        "--local",
        "--get",
        "branch.dry-run-base.worktreeBase",
    ]);
    assert!(
        meta.trim() == "main",
        "Expected 'main', got '{}'",
        meta.trim()
    );
}

// ===========================================================================
// change-base — invalid base
// ===========================================================================

#[test]
fn test_change_base_branch_invalid_base() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("invalid-base-test");

    let output = TestRepo::cw_at(&wt, &["change-base", "nonexistent-branch"]);
    assert!(!output.status.success());
}

// ===========================================================================
// resume — current worktree
// ===========================================================================

#[test]
fn test_resume_worktree_current_directory() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("resume-test");

    let output = TestRepo::cw_at(&wt, &["resume"]);
    // Resume without AI tool configured should succeed or print info
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("resume-test")
            || stdout.contains("session")
            || stdout.contains("Resume")
            || output.status.success(),
    );
}

// ===========================================================================
// resume — by branch name
// ===========================================================================

#[test]
fn test_resume_worktree_with_branch_name() {
    let repo = TestRepo::new();
    let _wt = repo.create_worktree("resume-branch");

    // Resume from main repo by branch name
    let output = repo.cw(&["resume", "resume-branch"]);
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("resume-branch")
            || stdout.contains("Switched")
            || stdout.contains("session")
            || output.status.success(),
    );
}

// ===========================================================================
// resume — nonexistent branch
// ===========================================================================

#[test]
fn test_resume_worktree_nonexistent_branch() {
    let repo = TestRepo::new();
    let output = repo.cw(&["resume", "nonexistent-branch"]);
    assert!(!output.status.success());
}

// ===========================================================================
// worktree status detection — stale
// ===========================================================================

#[test]
fn test_get_worktree_status_stale() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("stale-test");

    // Manually remove the directory
    std::fs::remove_dir_all(&wt).unwrap();

    // List should show stale status or handle gracefully
    let stdout = repo.cw_stdout(&["list"]);
    // The worktree should still appear (as stale) or be handled
    assert!(
        stdout.contains("stale-test") || stdout.contains("stale"),
        "Expected stale worktree in list"
    );
}

// ===========================================================================
// worktree status detection — modified
// ===========================================================================

#[test]
fn test_get_worktree_status_modified() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("modified-test");

    // Add uncommitted changes
    std::fs::write(wt.join("uncommitted.txt"), "uncommitted changes").unwrap();

    // Status/list should detect modified state
    let stdout = repo.cw_stdout(&["list"]);
    assert!(stdout.contains("modified-test"));
}

// ===========================================================================
// worktree status detection — merged (via git branch --merged fallback)
// ===========================================================================

#[test]
fn test_get_worktree_status_merged() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("merged-test");

    // Make a commit in the worktree
    TestRepo::commit_file_at(&wt, "feature.txt", "feature work", "feat: add feature");

    // Merge the feature branch into main (fast-forward)
    repo.git(&["merge", "merged-test"]);

    // The worktree's branch is now merged into main
    let stdout = repo.cw_stdout(&["list"]);
    assert!(
        stdout.contains("merged"),
        "Expected merged status in list output, got: {}",
        stdout
    );
}

// ===========================================================================
// worktree status detection — merged shows icon in tree
// ===========================================================================

#[test]
fn test_get_worktree_status_merged_tree() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("merged-tree-test");

    // Make a commit and merge into main
    TestRepo::commit_file_at(&wt, "feature.txt", "work", "feat: work");
    repo.git(&["merge", "merged-tree-test"]);

    let stdout = repo.cw_stdout(&["tree"]);
    assert!(
        stdout.contains("") || stdout.contains("merged"),
        "Expected merged icon or status in tree output, got: {}",
        stdout
    );
}

// ===========================================================================
// worktree status detection — clean
// ===========================================================================

#[test]
fn test_get_worktree_status_clean() {
    let repo = TestRepo::new();
    let _wt = repo.create_worktree("clean-test");

    let stdout = repo.cw_stdout(&["list"]);
    assert!(stdout.contains("clean-test"));
}

// ===========================================================================
// doctor
// ===========================================================================

#[test]
fn test_doctor() {
    let repo = TestRepo::new();
    let output = repo.cw(&["doctor"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("Health Check") || stdout.contains("health") || stdout.contains("Checking")
    );
}

// ===========================================================================
// config show
// ===========================================================================

#[test]
fn test_config_show() {
    let repo = TestRepo::new();
    let output = repo.cw(&["config", "show"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("AI Tool:") || stdout.contains("Config") || stdout.contains("config"));
}

// ===========================================================================
// path --list-branches
// ===========================================================================

#[test]
fn test_path_list_branches() {
    let repo = TestRepo::new();
    let output = repo.cw(&["_path", "--list-branches"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("main") || stdout.contains("master"));
}

// ===========================================================================
// diff — nonexistent branch
// ===========================================================================

#[test]
fn test_diff_nonexistent_branch() {
    let repo = TestRepo::new();
    let output = repo.cw(&["diff", "main", "nonexistent"]);
    assert!(!output.status.success());
}

// ===========================================================================
// prune — empty
// ===========================================================================

#[test]
fn test_prune_empty() {
    let repo = TestRepo::new();
    let output = repo.cw(&["prune"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(
        stdout.contains("stale")
            || stdout.contains("No stale")
            || stdout.contains("Prune")
            || stdout.contains("prune")
    );
}

// ===========================================================================
// tree (basic)
// ===========================================================================

#[test]
fn test_tree_in_repo() {
    let repo = TestRepo::new();
    let output = repo.cw(&["tree"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("(base repository)"));
}

// ===========================================================================
// stats (no worktrees)
// ===========================================================================

#[test]
fn test_stats_no_worktrees() {
    let repo = TestRepo::new();
    let output = repo.cw(&["stats"]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("No feature worktrees found"));
}

// ===========================================================================
// export creates file
// ===========================================================================

#[test]
fn test_export_creates_file() {
    let repo = TestRepo::new();
    let export_path = repo.path().join("test-export.json");
    let output = repo.cw(&["export", "--output", export_path.to_str().unwrap()]);
    assert!(output.status.success());
    assert!(export_path.exists());

    let content = std::fs::read_to_string(&export_path).unwrap();
    let parsed: serde_json::Value = serde_json::from_str(&content).unwrap();
    assert_eq!(
        parsed.get("export_version").unwrap().as_str().unwrap(),
        "1.0"
    );
}

// ===========================================================================
// import preview
// ===========================================================================

#[test]
fn test_import_preview() {
    let repo = TestRepo::new();
    let export_path = repo.path().join("import-test.json");
    repo.cw(&["export", "--output", export_path.to_str().unwrap()]);

    let output = repo.cw(&["import", export_path.to_str().unwrap()]);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Preview") || stdout.contains("preview"));
}

// ===========================================================================
// change-base — no metadata (manually created worktree)
// ===========================================================================

#[test]
fn test_change_base_branch_no_metadata() {
    let repo = TestRepo::new();

    // Create a branch and worktree manually (without metadata)
    repo.create_branch("manual-branch");
    let repo_name = repo.path().file_name().unwrap().to_str().unwrap();
    let manual_path = repo
        .path()
        .parent()
        .unwrap()
        .join(format!("{}-manual-worktree", repo_name));
    repo.git(&[
        "worktree",
        "add",
        manual_path.to_str().unwrap(),
        "manual-branch",
    ]);

    // The Rust implementation allows change-base on worktrees without pre-existing
    // metadata (it creates the metadata). Verify it works and sets the base.
    let output = repo.cw(&["change-base", "main", "manual-branch"]);
    let combined = format!(
        "{}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    assert!(
        output.status.success() || combined.contains("metadata") || combined.contains("error"),
        "Expected success or metadata error, got: {}",
        combined
    );

    // If successful, verify the metadata was created
    if output.status.success() {
        let meta = repo.git_stdout(&["config", "--get", "branch.manual-branch.worktreeBase"]);
        assert_eq!(meta.trim(), "main");
    }
}

// ===========================================================================
// change-base — with conflicts (rebase fails)
// ===========================================================================

#[test]
fn test_change_base_branch_with_conflicts() {
    let repo = TestRepo::new();

    // Create develop branch with conflicting change
    repo.git(&["checkout", "-b", "develop"]);
    std::fs::write(repo.path().join("conflict.txt"), "develop content").unwrap();
    repo.git(&["add", "."]);
    repo.git(&["commit", "-m", "Develop change"]);

    // Switch back to main
    repo.git(&["checkout", "main"]);

    // Create worktree from main with conflicting change
    let wt = repo.create_worktree("conflict-test");
    std::fs::write(wt.join("conflict.txt"), "main content").unwrap();
    TestRepo::git_at(&wt, &["add", "."]);
    TestRepo::git_at(&wt, &["commit", "-m", "Main change"]);

    // Try to change base to develop (should fail with conflicts)
    let output = TestRepo::cw_at(&wt, &["change-base", "develop"]);
    assert!(
        !output.status.success(),
        "Expected failure due to rebase conflicts"
    );

    // Base branch should NOT have changed
    let meta = repo.git_stdout(&[
        "config",
        "--local",
        "--get",
        "branch.conflict-test.worktreeBase",
    ]);
    assert_eq!(
        meta.trim(),
        "main",
        "Base branch should still be 'main' after failed rebase"
    );
}

// ===========================================================================
// sync — with conflicts (rebase fails)
// ===========================================================================

#[test]
fn test_sync_worktree_with_conflicts() {
    let repo = TestRepo::new();

    // Create develop branch with conflicting change
    repo.git(&["checkout", "-b", "develop"]);
    std::fs::write(repo.path().join("sync-conflict.txt"), "develop content").unwrap();
    repo.git(&["add", "."]);
    repo.git(&["commit", "-m", "Develop change"]);

    // Switch back to main
    repo.git(&["checkout", "main"]);

    // Create worktree from main
    let wt = repo.create_worktree("sync-conflict-test");

    // Make conflicting change in worktree
    std::fs::write(wt.join("sync-conflict.txt"), "main content").unwrap();
    TestRepo::git_at(&wt, &["add", "."]);
    TestRepo::git_at(&wt, &["commit", "-m", "Main change"]);

    // Update base to develop
    repo.git(&[
        "config",
        "--local",
        "branch.sync-conflict-test.worktreeBase",
        "develop",
    ]);

    // Sync should fail with conflicts or report conflict
    let output = TestRepo::cw_at(&wt, &["sync"]);
    let combined = format!(
        "{}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );
    assert!(
        !output.status.success()
            || combined.contains("conflict")
            || combined.contains("Conflict")
            || combined.contains("failed")
            || combined.contains("CONFLICT"),
        "Expected failure or conflict message during sync, got: {}",
        combined
    );
}

// ===========================================================================
// delete — from inside worktree (current directory)
// ===========================================================================

#[test]
#[cfg_attr(windows, ignore)] // Windows cannot delete cwd
fn test_delete_worktree_current_directory() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("delete-current");
    assert!(wt.exists());

    // Delete from inside the worktree
    let output = TestRepo::cw_at(&wt, &["delete", "delete-current"]);
    assert!(
        output.status.success(),
        "delete from inside worktree failed: {}{}",
        String::from_utf8_lossy(&output.stdout),
        String::from_utf8_lossy(&output.stderr),
    );

    assert!(!wt.exists());
}

// ===========================================================================
// delete — same branch and worktree name (not ambiguous)
// ===========================================================================

#[test]
fn test_delete_worktree_same_branch_and_worktree_name() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("matching");
    assert!(wt.exists());

    // "matching" as branch should work without ambiguity
    let output = repo.cw(&["delete", "matching"]);
    assert!(output.status.success());
    assert!(!wt.exists());
}

// ===========================================================================
// create_worktree — remote branch stores metadata
// ===========================================================================

#[test]
fn test_create_worktree_from_remote_stores_metadata() {
    let mut repo = TestRepo::new();
    let _remote = repo.setup_remote();

    repo.create_branch("meta-test");
    repo.git(&["push", "origin", "meta-test"]);
    repo.git(&["branch", "-D", "meta-test"]);

    let output = repo.cw(&["new", "meta-test", "--no-term"]);
    assert!(output.status.success());

    // Verify metadata is stored
    let base_branch = repo.git_stdout(&["config", "--get", "branch.meta-test.worktreeBase"]);
    assert_eq!(base_branch.trim(), "main");
}

// ===========================================================================
// get_worktree_status — active (running from within worktree)
// ===========================================================================

#[test]
fn test_get_worktree_status_active() {
    let repo = TestRepo::new();
    let wt = repo.create_worktree("active-test");

    // Run status from inside the worktree
    let stdout = TestRepo::cw_stdout_at(&wt, &["status"]);
    assert!(
        stdout.contains("active-test") || stdout.contains("active") || stdout.contains("Active"),
        "Expected active worktree info, got: {}",
        stdout
    );
}