-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathcmd_list.bats
More file actions
87 lines (75 loc) · 2.08 KB
/
cmd_list.bats
File metadata and controls
87 lines (75 loc) · 2.08 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
#!/usr/bin/env bats
# Tests for cmd_list in lib/commands/list.sh
load test_helper
setup() {
setup_integration_repo
source_gtr_commands
}
teardown() {
teardown_integration_repo
}
@test "cmd_list shows main repo" {
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"[main repo]"* ]]
}
@test "cmd_list shows created worktree" {
create_test_worktree "list-me"
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"list-me"* ]]
}
@test "cmd_list --porcelain outputs TSV format" {
create_test_worktree "porcelain-test"
local output
output=$(cmd_list --porcelain)
# First line: main repo
local first_line
first_line=$(echo "$output" | head -1)
[[ "$first_line" == *"$TEST_REPO"* ]]
# Should contain tab-separated fields
[[ "$output" == *$'\t'* ]]
}
@test "cmd_list --porcelain includes worktree branch and status" {
create_test_worktree "tsv-test"
local output
output=$(cmd_list --porcelain)
# Worktree line should have: path<tab>branch<tab>status
[[ "$output" == *"tsv-test"*$'\t'*"ok"* ]]
}
@test "cmd_list with no worktrees still works" {
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"Git Worktrees"* ]]
}
@test "cmd_list human format has header" {
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"BRANCH"* ]]
[[ "$output" == *"PATH"* ]]
}
@test "cmd_list from inside a worktree shows all worktrees" {
create_test_worktree "wt-inside"
cd "$TEST_WORKTREES_DIR/wt-inside"
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"[main repo]"* ]]
[[ "$output" == *"wt-inside"* ]]
[[ "$output" == *"$TEST_REPO"* ]]
}
@test "cmd_list --porcelain from inside a worktree includes main repo" {
create_test_worktree "wt-porcelain"
cd "$TEST_WORKTREES_DIR/wt-porcelain"
local output
output=$(cmd_list --porcelain)
[[ "$output" == *"$TEST_REPO"* ]]
[[ "$output" == *"wt-porcelain"* ]]
}
@test "cmd_list from a repo subdirectory shows the main repo root" {
mkdir -p "$TEST_REPO/subdir/nested"
cd "$TEST_REPO/subdir/nested"
run cmd_list
[ "$status" -eq 0 ]
[[ "$output" == *"$TEST_REPO"* ]]
[[ "$output" != *"subdir/..-worktrees"* ]]
}