Skip to content

Commit ea39574

Browse files
Test Userclaude
andcommitted
test: add tests for worktrees in non-standard locations
Covers edge case where worktrees are created outside the expected .worktrees/ directory (e.g., via manual git worktree add). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 91e2afb commit ea39574

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_cd.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,34 @@ test_cd_works_with_slashed_branch() {
5151
assert_contains "$PWD" "feature/auth" "Should work with slashed branch name"
5252
}
5353

54+
test_cd_works_with_nonstandard_location() {
55+
# Create worktree manually in non-standard location (not in .worktrees/)
56+
local custom_path="$TEST_TEMP/custom-location/my-worktree"
57+
mkdir -p "$(dirname "$custom_path")"
58+
cd "$TEST_TEMP/main"
59+
git worktree add -b custom-branch "$custom_path" >/dev/null 2>&1
60+
61+
wt cd custom-branch
62+
assert_contains "$PWD" "custom-location/my-worktree" "Should find worktree in non-standard location"
63+
}
64+
65+
test_cd_works_with_deeply_nested_nonstandard() {
66+
# Create worktree in deeply nested non-standard location
67+
local custom_path="$TEST_TEMP/some/deep/nested/path/worktree"
68+
mkdir -p "$(dirname "$custom_path")"
69+
cd "$TEST_TEMP/main"
70+
git worktree add -b nested-branch "$custom_path" >/dev/null 2>&1
71+
72+
wt cd nested-branch
73+
assert_contains "$PWD" "some/deep/nested/path/worktree" "Should find deeply nested worktree"
74+
}
75+
5476
# Register tests
5577
run_test "wt cd changes to worktree" test_cd_changes_to_worktree
5678
run_test "wt cd without arg goes to main" test_cd_no_arg_goes_to_main
5779
run_test "wt cd fails for nonexistent worktree" test_cd_fails_for_nonexistent
5880
run_test "wt cd works with short name" test_cd_works_with_short_name
5981
run_test "wt cd works with full path" test_cd_works_with_full_path
6082
run_test "wt cd works with slashed branch" test_cd_works_with_slashed_branch
83+
run_test "wt cd works with nonstandard location" test_cd_works_with_nonstandard_location
84+
run_test "wt cd works with deeply nested nonstandard" test_cd_works_with_deeply_nested_nonstandard

tests/test_rm.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ test_rm_with_full_path() {
7272
assert_success "Should remove worktree by full path"
7373
}
7474

75+
test_rm_works_with_nonstandard_location() {
76+
# Create worktree manually in non-standard location
77+
local custom_path="$TEST_TEMP/custom-location/my-worktree"
78+
mkdir -p "$(dirname "$custom_path")"
79+
cd "$TEST_TEMP/main"
80+
git worktree add -b custom-branch "$custom_path" >/dev/null 2>&1
81+
82+
wt rm custom-branch >/dev/null 2>&1
83+
[[ ! -d "$custom_path" ]]
84+
assert_success "Should remove worktree in non-standard location"
85+
}
86+
7587
# Register tests
7688
run_test "wt rm removes clean worktree" test_rm_removes_clean_worktree
7789
run_test "wt rm warns on dirty worktree" test_rm_warns_on_dirty_worktree
@@ -81,3 +93,4 @@ run_test "wt rm without arg removes current" test_rm_current_worktree_no_arg
8193
run_test "wt rm cds back to main" test_rm_current_worktree_cds_to_main
8294
run_test "wt rm fails for nonexistent" test_rm_fails_for_nonexistent
8395
run_test "wt rm with full path" test_rm_with_full_path
96+
run_test "wt rm works with nonstandard location" test_rm_works_with_nonstandard_location

0 commit comments

Comments
 (0)