-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharb.bats
More file actions
3670 lines (3102 loc) · 137 KB
/
arb.bats
File metadata and controls
3670 lines (3102 loc) · 137 KB
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
#!/usr/bin/env bats
setup() {
TEST_DIR="$(mktemp -d)"
TEST_DIR="$(cd "$TEST_DIR" && pwd -P)"
export PATH="$BATS_TEST_DIRNAME/../dist:$PATH"
# Initialize arb root first
mkdir -p "$TEST_DIR/project"
cd "$TEST_DIR/project"
arb init >/dev/null 2>&1
# Create bare origin repos and clone into .arb/repos/
git init --bare "$TEST_DIR/origin/repo-a.git" >/dev/null 2>&1
git clone "$TEST_DIR/origin/repo-a.git" "$TEST_DIR/project/.arb/repos/repo-a" >/dev/null 2>&1
(cd "$TEST_DIR/project/.arb/repos/repo-a" && git commit --allow-empty -m "init" && git push) >/dev/null 2>&1
git init --bare "$TEST_DIR/origin/repo-b.git" >/dev/null 2>&1
git clone "$TEST_DIR/origin/repo-b.git" "$TEST_DIR/project/.arb/repos/repo-b" >/dev/null 2>&1
(cd "$TEST_DIR/project/.arb/repos/repo-b" && git commit --allow-empty -m "init" && git push) >/dev/null 2>&1
}
teardown() {
rm -rf "$TEST_DIR"
}
# ── version & help ───────────────────────────────────────────────
@test "arb --version outputs version number" {
run arb --version
[ "$status" -eq 0 ]
[[ "$output" =~ ^Arborist\ [0-9]+\.[0-9]+\.[0-9]+ ]]
}
@test "arb version is treated as unknown command" {
run arb version
[ "$status" -ne 0 ]
}
@test "arb -v outputs version number" {
run arb -v
[ "$status" -eq 0 ]
[[ "$output" =~ ^Arborist\ [0-9]+\.[0-9]+\.[0-9]+ ]]
}
# ── bare arb (shows help) ────────────────────────────────────────
@test "bare arb shows help with usage and commands" {
run arb
[[ "$output" == *"Usage:"* ]]
[[ "$output" == *"Commands:"* ]]
}
# ── repos ─────────────────────────────────────────────────────────
@test "arb repos lists cloned repo names" {
run arb repos
[ "$status" -eq 0 ]
[[ "$output" == *"repo-a"* ]]
[[ "$output" == *"repo-b"* ]]
}
@test "arb repos outputs one repo per line" {
run arb repos
[ "$status" -eq 0 ]
local count
count="$(echo "$output" | wc -l | tr -d ' ')"
[ "$count" -eq 2 ]
}
@test "arb repos outside arb root fails" {
cd /tmp
run arb repos
[ "$status" -ne 0 ]
[[ "$output" == *"Not inside an arb root"* ]]
}
# ── help ──────────────────────────────────────────────────────────
@test "arb help shows full usage text" {
run arb help
[ "$status" -eq 0 ]
[[ "$output" == *"Usage:"* ]]
[[ "$output" == *"repos"* ]]
}
@test "arb --help shows usage" {
run arb --help
[ "$status" -eq 0 ]
[[ "$output" == *"Usage:"* ]]
}
@test "arb -h shows usage" {
run arb -h
[ "$status" -eq 0 ]
[[ "$output" == *"Usage:"* ]]
}
@test "unknown command shows error" {
run arb nonsense
[ "$status" -ne 0 ]
[[ "$output" == *"unknown command"* ]]
}
@test "commands outside arb root fail with helpful message" {
cd /tmp
run arb list
[ "$status" -ne 0 ]
[[ "$output" == *"Not inside an arb root"* ]]
}
# ── init ─────────────────────────────────────────────────────────
@test "arb init creates .arb/repos/" {
local dir="$TEST_DIR/fresh"
mkdir -p "$dir"
cd "$dir"
run arb init
[ "$status" -eq 0 ]
[ -d "$dir/.arb" ]
[ -d "$dir/.arb/repos" ]
[[ "$output" == *"arb clone"* ]]
[[ "$output" == *"arb create"* ]]
}
@test "arb init on existing root fails" {
run arb init
[ "$status" -ne 0 ]
[[ "$output" == *"Already initialized"* ]]
}
@test "arb init inside workspace fails" {
run arb create ws-init-test -a
[ "$status" -eq 0 ]
cd "$TEST_DIR/project/ws-init-test/repo-a"
run arb init
[ "$status" -ne 0 ]
[[ "$output" == *"inside existing arb root"* ]]
}
@test "arb init with path inside arb root fails" {
run arb init "$TEST_DIR/project/some-subdir"
[ "$status" -ne 0 ]
[[ "$output" == *"inside existing arb root"* ]]
}
# ── clone ────────────────────────────────────────────────────────
@test "arb clone clones a repo into repos/" {
run arb clone "$TEST_DIR/origin/repo-a.git" clone-test
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/.arb/repos/clone-test/.git" ]
}
@test "arb clone derives name from URL" {
git init --bare "$TEST_DIR/origin/derived-name.git" >/dev/null 2>&1
run arb clone "$TEST_DIR/origin/derived-name.git"
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/.arb/repos/derived-name/.git" ]
}
@test "arb clone detaches HEAD in canonical repo" {
run arb clone "$TEST_DIR/origin/repo-a.git" detach-test
[ "$status" -eq 0 ]
run git -C "$TEST_DIR/project/.arb/repos/detach-test" status
[[ "$output" == *"HEAD detached"* ]]
}
@test "arb clone allows workspace on default branch" {
run arb clone "$TEST_DIR/origin/repo-a.git" main-test
[ "$status" -eq 0 ]
# Creating a workspace on main should succeed because HEAD is detached
run arb create main-ws --branch main main-test
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/main-ws/main-test" ]
local branch
branch="$(git -C "$TEST_DIR/project/main-ws/main-test" branch --show-current)"
[ "$branch" = "main" ]
}
@test "arb clone fails if repo already exists" {
run arb clone "$TEST_DIR/origin/repo-a.git" repo-a
[ "$status" -ne 0 ]
[[ "$output" == *"already cloned"* ]]
}
@test "arb clone fails with invalid path" {
run arb clone "/nonexistent/path/repo.git"
[ "$status" -ne 0 ]
[[ "$output" == *"Clone failed"* ]]
}
@test "arb clone without args fails" {
run arb clone
[ "$status" -ne 0 ]
[[ "$output" == *"missing required argument"* ]]
}
# ── create ───────────────────────────────────────────────────────
@test "arb create creates workspace with .arbws/config" {
arb create my-feature --all-repos
[ -d "$TEST_DIR/project/my-feature" ]
[ -d "$TEST_DIR/project/my-feature/.arbws" ]
[ -f "$TEST_DIR/project/my-feature/.arbws/config" ]
}
@test ".arbws/config contains correct branch" {
arb create my-feature --all-repos
run cat "$TEST_DIR/project/my-feature/.arbws/config"
[[ "$output" == *"branch = my-feature"* ]]
}
@test "arb create with repos creates worktrees" {
arb create my-feature repo-a repo-b
[ -d "$TEST_DIR/project/my-feature/repo-a" ]
[ -d "$TEST_DIR/project/my-feature/repo-b" ]
}
@test "arb create --all-repos creates worktrees for all repos" {
arb create all-ws --all-repos
[ -d "$TEST_DIR/project/all-ws/repo-a" ]
[ -d "$TEST_DIR/project/all-ws/repo-b" ]
}
@test "arb create -a creates worktrees for all repos" {
arb create all-ws -a
[ -d "$TEST_DIR/project/all-ws/repo-a" ]
[ -d "$TEST_DIR/project/all-ws/repo-b" ]
}
@test "arb create --branch stores custom branch in config" {
arb create payments --branch feat/payments repo-a
run cat "$TEST_DIR/project/payments/.arbws/config"
[[ "$output" == *"branch = feat/payments"* ]]
}
@test "arb create -b stores custom branch in config" {
arb create payments -b feat/payments repo-a
run cat "$TEST_DIR/project/payments/.arbws/config"
[[ "$output" == *"branch = feat/payments"* ]]
}
@test "arb create derives branch from workspace name (lowercased)" {
arb create MyFeature --all-repos
run cat "$TEST_DIR/project/MyFeature/.arbws/config"
[[ "$output" == *"branch = myfeature"* ]]
}
@test "arb create attaches existing branch" {
# Create a branch with unique content directly in the canonical repo
git -C "$TEST_DIR/project/.arb/repos/repo-a" checkout -b reuse-me >/dev/null 2>&1
echo "branch-content" > "$TEST_DIR/project/.arb/repos/repo-a/marker.txt"
git -C "$TEST_DIR/project/.arb/repos/repo-a" add marker.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/.arb/repos/repo-a" commit -m "marker" >/dev/null 2>&1
git -C "$TEST_DIR/project/.arb/repos/repo-a" checkout main >/dev/null 2>&1
# Create a workspace that reuses the existing branch
arb create reuse-ws --branch reuse-me repo-a
# The worktree should be on the existing branch with the prior commit
[ -f "$TEST_DIR/project/reuse-ws/repo-a/marker.txt" ]
# Verify it's on the correct branch
local branch
branch="$(git -C "$TEST_DIR/project/reuse-ws/repo-a" branch --show-current)"
[ "$branch" = "reuse-me" ]
}
@test "arb create produces no stdout" {
run bash -c 'arb create foo repo-a 2>/dev/null'
[ -z "$output" ]
}
@test "arb create shows workspace path" {
run arb create path-test repo-a
[ "$status" -eq 0 ]
[[ "$output" == *"$TEST_DIR/project/path-test"* ]]
}
@test "arb create with duplicate workspace name fails" {
arb create my-feature repo-a
run arb create my-feature repo-b
[ "$status" -ne 0 ]
[[ "$output" == *"already exists"* ]]
}
@test "arb create with no repos creates empty workspace" {
run arb create no-repos-ws
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/no-repos-ws/.arbws" ]
[[ "$output" == *"No repos added"* ]]
}
@test "arb create without name fails" {
run arb create
[ "$status" -ne 0 ]
[[ "$output" == *"Usage: arb create"* ]]
}
@test "arb create --branch without value fails" {
run arb create foo --branch
[ "$status" -ne 0 ]
[[ "$output" == *"argument missing"* ]]
}
@test "arb create with invalid branch name fails" {
run arb create bad-ws --branch "bad branch name with spaces" repo-a
[ "$status" -ne 0 ]
[[ "$output" == *"Invalid branch name"* ]]
}
@test "arb create rejects name with slash" {
run arb create "bad/name"
[ "$status" -ne 0 ]
[[ "$output" == *"must not contain '/'"* ]]
}
@test "arb create rejects name with path traversal" {
run arb create "foo..bar"
[ "$status" -ne 0 ]
[[ "$output" == *"must not contain '..'"* ]]
}
@test "arb create rejects name with whitespace" {
run arb create "bad name"
[ "$status" -ne 0 ]
[[ "$output" == *"must not contain whitespace"* ]]
}
# ── add ──────────────────────────────────────────────────────────
@test "arb add reads branch from config" {
arb create my-feature --branch feat/custom repo-b
cd "$TEST_DIR/project/my-feature"
arb add repo-a
[ -d "$TEST_DIR/project/my-feature/repo-a" ]
# Verify the worktree is on the correct branch
local branch
branch="$(git -C "$TEST_DIR/project/my-feature/repo-a" branch --show-current)"
[ "$branch" = "feat/custom" ]
}
@test "arb add skips repo already in workspace" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb add repo-a
[[ "$output" == *"already exists"* ]] || [[ "$output" == *"Skipping"* ]] || [[ "$output" == *"skipping"* ]] || [[ "$output" == *"Skipped"* ]]
}
@test "arb add with nonexistent repo fails" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb add no-such-repo
[[ "$output" == *"not a git repo"* ]] || [[ "$output" == *"failed"* ]]
}
@test "arb add without workspace context fails" {
run arb add repo-a
[ "$status" -ne 0 ]
[[ "$output" == *"Not inside a workspace"* ]]
}
@test "arb add without args fails in non-TTY" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb add
[ "$status" -ne 0 ]
[[ "$output" == *"No repos specified"* ]]
[[ "$output" == *"--all-repos"* ]]
}
@test "arb add -a adds all remaining repos" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb add -a
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/my-feature/repo-b" ]
}
@test "arb add --all-repos adds all remaining repos" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb add --all-repos
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/my-feature/repo-b" ]
}
@test "arb add -a when all repos already present errors" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
run arb add -a
[ "$status" -ne 0 ]
[[ "$output" == *"All repos are already in this workspace"* ]]
}
@test "arb add recovers from stale worktree reference" {
arb create my-feature repo-a repo-b
# Remove workspace dir without git worktree remove (leaves stale reference)
rm -rf "$TEST_DIR/project/my-feature"
# Re-create workspace and re-add — should succeed thanks to proactive prune
mkdir -p "$TEST_DIR/project/my-feature/.arbws"
echo "branch = my-feature" > "$TEST_DIR/project/my-feature/.arbws/config"
cd "$TEST_DIR/project/my-feature"
run arb add repo-a repo-b
[ "$status" -eq 0 ]
[ -d "$TEST_DIR/project/my-feature/repo-a" ]
[ -d "$TEST_DIR/project/my-feature/repo-b" ]
}
# ── drop ─────────────────────────────────────────────────────────
@test "arb drop removes a repo from workspace" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
arb drop repo-b
[ ! -d "$TEST_DIR/project/my-feature/repo-b" ]
[ -d "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb drop skips repo with uncommitted changes without --force" {
arb create my-feature repo-a repo-b
echo "dirty" > "$TEST_DIR/project/my-feature/repo-a/dirty.txt"
cd "$TEST_DIR/project/my-feature"
run arb drop repo-a
[[ "$output" == *"uncommitted changes"* ]]
[ -d "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb drop --force removes repo even with uncommitted changes" {
arb create my-feature repo-a repo-b
echo "dirty" > "$TEST_DIR/project/my-feature/repo-a/dirty.txt"
cd "$TEST_DIR/project/my-feature"
arb drop --force repo-a
[ ! -d "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb drop -f removes repo even with uncommitted changes" {
arb create my-feature repo-a repo-b
echo "dirty" > "$TEST_DIR/project/my-feature/repo-a/dirty.txt"
cd "$TEST_DIR/project/my-feature"
arb drop -f repo-a
[ ! -d "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb drop --delete-branch also deletes local branch" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
arb drop --delete-branch repo-b
[ ! -d "$TEST_DIR/project/my-feature/repo-b" ]
run git -C "$TEST_DIR/project/.arb/repos/repo-b" show-ref --verify "refs/heads/my-feature"
[ "$status" -ne 0 ]
}
@test "arb drop skips repo not in workspace" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb drop repo-b
[[ "$output" == *"not in this workspace"* ]]
}
@test "arb drop without args fails in non-TTY" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb drop
[ "$status" -ne 0 ]
[[ "$output" == *"No repos specified"* ]]
[[ "$output" == *"--all-repos"* ]]
}
@test "arb drop -a drops all repos from workspace" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
run arb drop -a
[ "$status" -eq 0 ]
[ ! -d "$TEST_DIR/project/my-feature/repo-a" ]
[ ! -d "$TEST_DIR/project/my-feature/repo-b" ]
}
@test "arb drop --all-repos drops all repos from workspace" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
run arb drop --all-repos
[ "$status" -eq 0 ]
[ ! -d "$TEST_DIR/project/my-feature/repo-a" ]
[ ! -d "$TEST_DIR/project/my-feature/repo-b" ]
}
@test "arb drop -a on empty workspace errors" {
mkdir -p "$TEST_DIR/project/empty-ws/.arbws"
echo "branch = empty" > "$TEST_DIR/project/empty-ws/.arbws/config"
cd "$TEST_DIR/project/empty-ws"
run arb drop -a
[ "$status" -ne 0 ]
[[ "$output" == *"No repos in this workspace"* ]]
}
@test "arb drop without workspace context fails" {
run arb drop repo-a
[ "$status" -ne 0 ]
[[ "$output" == *"Not inside a workspace"* ]]
}
# ── remove ───────────────────────────────────────────────────────
@test "arb remove --force removes worktrees, branches, workspace dir" {
arb create my-feature repo-a repo-b
arb remove my-feature --force
[ ! -d "$TEST_DIR/project/my-feature" ]
# Branch should be deleted from canonical repo
run git -C "$TEST_DIR/project/.arb/repos/repo-a" show-ref --verify "refs/heads/my-feature"
[ "$status" -ne 0 ]
}
@test "arb remove -f removes worktrees, branches, workspace dir" {
arb create my-feature repo-a repo-b
arb remove my-feature -f
[ ! -d "$TEST_DIR/project/my-feature" ]
run git -C "$TEST_DIR/project/.arb/repos/repo-a" show-ref --verify "refs/heads/my-feature"
[ "$status" -ne 0 ]
}
@test "arb remove --force --delete-remote deletes remote branches" {
arb create my-feature repo-a
# Push the branch to the remote first
git -C "$TEST_DIR/project/my-feature/repo-a" push -u origin my-feature >/dev/null 2>&1
arb remove my-feature --force --delete-remote
# Remote branch should be gone
run git -C "$TEST_DIR/project/.arb/repos/repo-a" show-ref --verify "refs/remotes/origin/my-feature"
[ "$status" -ne 0 ]
}
@test "arb remove -f -d deletes remote branches" {
arb create my-feature repo-a
git -C "$TEST_DIR/project/my-feature/repo-a" push -u origin my-feature >/dev/null 2>&1
arb remove my-feature -f -d
run git -C "$TEST_DIR/project/.arb/repos/repo-a" show-ref --verify "refs/remotes/origin/my-feature"
[ "$status" -ne 0 ]
}
@test "arb remove --force --delete-remote reports failed remote delete" {
arb create my-feature repo-a repo-b
git -C "$TEST_DIR/project/my-feature/repo-a" push -u origin my-feature >/dev/null 2>&1
git -C "$TEST_DIR/project/my-feature/repo-b" push -u origin my-feature >/dev/null 2>&1
# Make repo-b's remote unreachable so the push --delete fails
mv "$TEST_DIR/origin/repo-b.git" "$TEST_DIR/origin/repo-b.git.bak"
run arb remove my-feature --force --delete-remote
[ "$status" -eq 0 ]
[ ! -d "$TEST_DIR/project/my-feature" ]
[[ "$output" == *"failed to delete remote branch"* ]]
# Restore for teardown
mv "$TEST_DIR/origin/repo-b.git.bak" "$TEST_DIR/origin/repo-b.git"
}
@test "arb remove aborts on non-interactive input" {
arb create my-feature repo-a
run bash -c 'echo "" | arb remove my-feature'
[ "$status" -ne 0 ]
[[ "$output" == *"not a terminal"* ]]
}
@test "arb remove nonexistent workspace fails" {
run arb remove ghost --force
[ "$status" -ne 0 ]
[[ "$output" == *"No workspace found"* ]]
}
@test "arb remove without args fails in non-TTY" {
run arb remove
[ "$status" -ne 0 ]
[[ "$output" == *"No workspace specified"* ]]
}
@test "arb remove multiple workspaces with --force" {
arb create ws-a repo-a
arb create ws-b repo-b
arb remove ws-a ws-b --force
[ ! -d "$TEST_DIR/project/ws-a" ]
[ ! -d "$TEST_DIR/project/ws-b" ]
}
@test "arb remove multiple workspaces removes all" {
arb create ws-one repo-a
arb create ws-two repo-b
run arb remove ws-one ws-two --force
[ "$status" -eq 0 ]
[ ! -d "$TEST_DIR/project/ws-one" ]
[ ! -d "$TEST_DIR/project/ws-two" ]
}
@test "arb remove refuses workspace with merge conflict" {
arb create my-feature repo-a
local wt="$TEST_DIR/project/my-feature/repo-a"
# Create a file on the feature branch
echo "feature" > "$wt/conflict.txt"
git -C "$wt" add conflict.txt
git -C "$wt" commit -m "feature change" >/dev/null 2>&1
# Create a conflicting change on the default branch via the canonical repo
local canonical="$TEST_DIR/project/.arb/repos/repo-a"
local default_branch
default_branch="$(git -C "$canonical" symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||')"
git -C "$canonical" checkout "$default_branch" >/dev/null 2>&1
echo "main" > "$canonical/conflict.txt"
git -C "$canonical" add conflict.txt
git -C "$canonical" commit -m "main change" >/dev/null 2>&1
git -C "$canonical" push >/dev/null 2>&1
git -C "$canonical" checkout --detach HEAD >/dev/null 2>&1
# Fetch and attempt merge to create conflict state
git -C "$wt" fetch origin >/dev/null 2>&1
git -C "$wt" merge "origin/$default_branch" >/dev/null 2>&1 || true
# Status should show conflicts
run arb -w my-feature status
[[ "$output" == *"conflicts"* ]]
# Remove without --force should refuse (non-TTY exits before at-risk check)
run arb remove my-feature
[ "$status" -ne 0 ]
# Workspace should still exist
[ -d "$TEST_DIR/project/my-feature" ]
# Force remove should succeed
arb remove my-feature --force
[ ! -d "$TEST_DIR/project/my-feature" ]
}
# ── list ─────────────────────────────────────────────────────────
@test "arb list shows workspaces" {
arb create ws-one repo-a
arb create ws-two repo-b
run arb list
[[ "$output" == *"ws-one"* ]]
[[ "$output" == *"ws-two"* ]]
}
@test "arb list highlights active workspace" {
arb create ws-one repo-a
arb create ws-two repo-b
cd "$TEST_DIR/project/ws-one"
run arb list
# ws-one should be marked with *
[[ "$output" == *"* ws-one"* ]] || [[ "$output" == *"*ws-one"* ]]
}
@test "arb list ignores dirs without .arbws" {
mkdir -p "$TEST_DIR/project/not-a-workspace"
arb create real-ws --all-repos
run arb list
[[ "$output" == *"real-ws"* ]]
[[ "$output" != *"not-a-workspace"* ]]
}
@test "arb list piped to cat has no escape sequences" {
arb create ws-one repo-a
run bash -c 'arb list | cat'
# Output should not contain ESC characters
[[ "$output" != *$'\033'* ]]
}
@test "arb list with no workspaces shows hint" {
run arb list
[ "$status" -eq 0 ]
[[ "$output" == *"arb create"* ]]
}
@test "arb list shows repo count" {
arb create ws-one repo-a repo-b
run arb list
[[ "$output" == *"2"* ]]
}
@test "arb list shows ok status for fresh branch with no commits" {
arb create ws-one repo-a
run arb list
[[ "$output" == *"ok"* ]]
[[ "$output" != *"unpushed"* ]]
}
@test "arb list shows ok status when pushed" {
arb create ws-one repo-a
echo "change" > "$TEST_DIR/project/ws-one/repo-a/f.txt"
git -C "$TEST_DIR/project/ws-one/repo-a" add f.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/ws-one/repo-a" commit -m "commit" >/dev/null 2>&1
git -C "$TEST_DIR/project/ws-one/repo-a" push -u origin ws-one >/dev/null 2>&1
(cd "$TEST_DIR/project/.arb/repos/repo-a" && git fetch origin) >/dev/null 2>&1
run arb list
[[ "$output" == *"ok"* ]]
}
@test "arb list shows UPPERCASE headers" {
arb create ws-one repo-a
run arb list
[[ "$output" == *"WORKSPACE"* ]]
[[ "$output" == *"BRANCH"* ]]
[[ "$output" == *"REPOS"* ]]
[[ "$output" == *"STATUS"* ]]
}
@test "arb list shows branch name" {
arb create ws-one --branch feat/payments repo-a
run arb list
[[ "$output" == *"feat/payments"* ]]
}
@test "arb list shows BASE column for stacked workspaces" {
git -C "$TEST_DIR/project/.arb/repos/repo-a" checkout -b feat/auth >/dev/null 2>&1
echo "auth" > "$TEST_DIR/project/.arb/repos/repo-a/auth.txt"
git -C "$TEST_DIR/project/.arb/repos/repo-a" add auth.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/.arb/repos/repo-a" commit -m "auth" >/dev/null 2>&1
git -C "$TEST_DIR/project/.arb/repos/repo-a" push -u origin feat/auth >/dev/null 2>&1
git -C "$TEST_DIR/project/.arb/repos/repo-a" checkout --detach >/dev/null 2>&1
arb create stacked --base feat/auth -b feat/auth-ui repo-a
arb create normal repo-b
run arb list
[[ "$output" == *"BASE"* ]]
[[ "$output" == *"feat/auth"* ]]
}
@test "arb list hides BASE column when no stacked workspaces" {
arb create ws-one repo-a
run arb list
[[ "$output" != *"BASE"* ]]
}
@test "arb list --quick shows workspaces without STATUS column" {
arb create ws-one repo-a
arb create ws-two repo-b
run arb list --quick
[ "$status" -eq 0 ]
[[ "$output" == *"ws-one"* ]]
[[ "$output" == *"ws-two"* ]]
[[ "$output" == *"WORKSPACE"* ]]
[[ "$output" == *"BRANCH"* ]]
[[ "$output" == *"REPOS"* ]]
[[ "$output" != *"STATUS"* ]]
[[ "$output" != *"ok"* ]]
}
@test "arb list --quick -q shorthand works" {
arb create ws-one repo-a
run arb list -q
[ "$status" -eq 0 ]
[[ "$output" == *"ws-one"* ]]
[[ "$output" != *"STATUS"* ]]
}
@test "arb list piped output has no progress escape sequences" {
arb create ws-one repo-a
arb create ws-two repo-b
result=$(arb list 2>/dev/null)
# stdout should not contain cursor movement sequences
[[ "$result" != *$'\033['*'A'* ]]
}
# ── path ─────────────────────────────────────────────────────────
@test "arb path returns correct path" {
arb create my-feature --all-repos
run arb path my-feature
[ "$output" = "$TEST_DIR/project/my-feature" ]
}
@test "arb path with no argument returns arb root from workspace" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature/repo-a"
run arb path
[ "$output" = "$TEST_DIR/project" ]
}
@test "arb path with subpath returns repo path" {
arb create my-feature repo-a
run arb path my-feature/repo-a
[ "$output" = "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb path with no argument outside workspace returns arb root" {
run arb path
[ "$status" -eq 0 ]
[ "$output" = "$TEST_DIR/project" ]
}
@test "arb path with invalid subpath fails" {
arb create my-feature repo-a
run arb path my-feature/nonexistent
[ "$status" -ne 0 ]
[[ "$output" == *"not found in workspace"* ]]
}
@test "arb path with nonexistent workspace fails" {
run arb path does-not-exist
[ "$status" -ne 0 ]
[[ "$output" == *"does not exist"* ]]
}
# ── cd ───────────────────────────────────────────────────────────
@test "arb cd prints correct workspace path" {
arb create my-feature --all-repos
run arb cd my-feature
[ "$status" -eq 0 ]
[ "$output" = "$TEST_DIR/project/my-feature" ]
}
@test "arb cd with subpath prints correct worktree path" {
arb create my-feature repo-a
run arb cd my-feature/repo-a
[ "$status" -eq 0 ]
[ "$output" = "$TEST_DIR/project/my-feature/repo-a" ]
}
@test "arb cd with nonexistent workspace fails" {
run arb cd does-not-exist
[ "$status" -ne 0 ]
[[ "$output" == *"does not exist"* ]]
}
@test "arb cd with nonexistent subpath fails" {
arb create my-feature repo-a
run arb cd my-feature/nonexistent
[ "$status" -ne 0 ]
[[ "$output" == *"not found in workspace"* ]]
}
@test "arb cd with no arg in non-TTY fails" {
run arb cd
[ "$status" -ne 0 ]
[[ "$output" == *"Usage: arb cd"* ]]
}
@test "arb cd rejects non-workspace directory" {
mkdir -p "$TEST_DIR/project/not-a-workspace"
run arb cd not-a-workspace
[ "$status" -ne 0 ]
[[ "$output" == *"does not exist"* ]]
}
# ── status ───────────────────────────────────────────────────────
@test "arb status shows base branch name" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"main"* ]]
}
@test "arb status shows aligned when on same commit as default branch" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"aligned"* ]]
}
@test "arb status shows current branch name" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"my-feature"* ]]
}
@test "arb status shows origin/ prefix in remote column" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"origin/my-feature"* ]]
}
@test "arb status shows clean for repos with no local changes" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"clean"* ]]
}
@test "arb status shows ahead count after local commit" {
arb create my-feature repo-a
echo "new" > "$TEST_DIR/project/my-feature/repo-a/new.txt"
git -C "$TEST_DIR/project/my-feature/repo-a" add new.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/my-feature/repo-a" commit -m "ahead" >/dev/null 2>&1
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"1 ahead"* ]]
}
@test "arb status shows behind count when default branch is ahead" {
arb create my-feature repo-a
# Add a commit to origin's default branch
(cd "$TEST_DIR/project/.arb/repos/repo-a" && echo "upstream" > upstream.txt && git add upstream.txt && git commit -m "upstream" && git push) >/dev/null 2>&1
cd "$TEST_DIR/project/my-feature"
arb fetch >/dev/null 2>&1
run arb status
[[ "$output" == *"1 behind"* ]]
}
@test "arb status shows not pushed when branch not on remote" {
arb create my-feature repo-a
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"not pushed"* ]]
}
@test "arb status shows aligned after push with no new commits" {
arb create my-feature repo-a
echo "change" > "$TEST_DIR/project/my-feature/repo-a/f.txt"
git -C "$TEST_DIR/project/my-feature/repo-a" add f.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/my-feature/repo-a" commit -m "commit" >/dev/null 2>&1
git -C "$TEST_DIR/project/my-feature/repo-a" push -u origin my-feature >/dev/null 2>&1
cd "$TEST_DIR/project/my-feature"
arb fetch >/dev/null 2>&1
run arb status
[[ "$output" == *"aligned"* ]]
}
@test "arb status shows staged count" {
arb create my-feature repo-a
echo "staged" > "$TEST_DIR/project/my-feature/repo-a/staged.txt"
git -C "$TEST_DIR/project/my-feature/repo-a" add staged.txt >/dev/null 2>&1
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"staged"* ]]
}
@test "arb status shows modified count" {
arb create my-feature repo-a
# Create a tracked file first
echo "orig" > "$TEST_DIR/project/my-feature/repo-a/tracked.txt"
git -C "$TEST_DIR/project/my-feature/repo-a" add tracked.txt >/dev/null 2>&1
git -C "$TEST_DIR/project/my-feature/repo-a" commit -m "add tracked" >/dev/null 2>&1
# Now modify it
echo "changed" > "$TEST_DIR/project/my-feature/repo-a/tracked.txt"
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"modified"* ]]
}
@test "arb status shows untracked count" {
arb create my-feature repo-a
echo "untracked" > "$TEST_DIR/project/my-feature/repo-a/untracked.txt"
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"untracked"* ]]
}
@test "arb status shows no repos message for empty workspace" {
mkdir -p "$TEST_DIR/project/empty-ws/.arbws"
echo "branch = empty" > "$TEST_DIR/project/empty-ws/.arbws/config"
cd "$TEST_DIR/project/empty-ws"
run arb status
[[ "$output" == *"(no repos)"* ]]
}
@test "arb status ignores non-git dirs in workspace" {
arb create my-feature repo-a
mkdir -p "$TEST_DIR/project/my-feature/stray-dir"
cd "$TEST_DIR/project/my-feature"
run arb status
[[ "$output" == *"repo-a"* ]]
[[ "$output" != *"stray-dir"* ]]
}
@test "arb status without workspace context fails" {
run arb status
[ "$status" -ne 0 ]
[[ "$output" == *"Not inside a workspace"* ]]
}
@test "arb status --dirty shows only dirty repos" {
arb create my-feature repo-a repo-b
echo "dirty" > "$TEST_DIR/project/my-feature/repo-a/dirty.txt"
cd "$TEST_DIR/project/my-feature"
run arb status --dirty
[[ "$output" == *"repo-a"* ]]
[[ "$output" != *"repo-b"* ]]
}
@test "arb status -d shows only dirty repos" {
arb create my-feature repo-a repo-b
echo "dirty" > "$TEST_DIR/project/my-feature/repo-a/dirty.txt"
cd "$TEST_DIR/project/my-feature"
run arb status -d
[[ "$output" == *"repo-a"* ]]
[[ "$output" != *"repo-b"* ]]
}
@test "arb status --dirty shows no repos when all clean" {
arb create my-feature repo-a repo-b
cd "$TEST_DIR/project/my-feature"
run arb status --dirty
[ "$status" -eq 0 ]
[[ "$output" == *"(no repos)"* ]]
}