Skip to content

Commit 48113d3

Browse files
fix: use main worktree path for all path calculations
When running commands from inside a worktree, several functions incorrectly used the current worktree's path instead of the main worktree's path for calculating directories and finding config files. Fixed functions: - _wt_find_worktree: worktree lookup now works from any worktree - _wt_new: creates worktrees in correct location from any worktree - _wt_up/_wt_down: finds .cursor/worktrees.json in main worktree 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a134caa commit 48113d3

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

wt.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,12 @@ _wt_new() {
273273
return 1
274274
fi
275275

276+
local main_worktree
277+
main_worktree=$(_wt_get_main_worktree)
276278
local base_name
277-
base_name=$(_wt_get_base_name "$repo_root")
279+
base_name=$(basename "$main_worktree")
278280
local parent_dir
279-
parent_dir=$(dirname "$repo_root")
281+
parent_dir=$(dirname "$main_worktree")
280282

281283
local branch_name
282284
local worktree_path
@@ -371,10 +373,10 @@ _wt_new() {
371373
fi
372374
fi
373375

374-
_wt_run_setup_commands "$repo_root" "$worktree_path"
376+
_wt_run_setup_commands "$main_worktree" "$worktree_path"
375377

376378
if [[ "$run_up" == true ]]; then
377-
_wt_run_up_commands "$repo_root" "$worktree_path"
379+
_wt_run_up_commands "$main_worktree" "$worktree_path"
378380
fi
379381

380382
cd "$worktree_path" || return 1
@@ -396,7 +398,9 @@ _wt_up() {
396398
return 1
397399
fi
398400

399-
_wt_run_up_commands "$repo_root" "$repo_root"
401+
local main_worktree
402+
main_worktree=$(_wt_get_main_worktree)
403+
_wt_run_up_commands "$main_worktree" "$repo_root"
400404
}
401405

402406
_wt_down() {
@@ -407,7 +411,9 @@ _wt_down() {
407411
return 1
408412
fi
409413

410-
_wt_run_down_commands "$repo_root" "$repo_root"
414+
local main_worktree
415+
main_worktree=$(_wt_get_main_worktree)
416+
_wt_run_down_commands "$main_worktree" "$repo_root"
411417
}
412418

413419
_wt_ls() {
@@ -461,12 +467,12 @@ _wt_find_worktree() {
461467
return 1
462468
fi
463469

464-
local base_name
465-
base_name=$(_wt_get_base_name "$repo_root")
466-
local parent_dir
467-
parent_dir=$(dirname "$repo_root")
468470
local main_worktree
469471
main_worktree=$(_wt_get_main_worktree)
472+
local base_name
473+
base_name=$(basename "$main_worktree")
474+
local parent_dir
475+
parent_dir=$(dirname "$main_worktree")
470476

471477
# Check if name matches main worktree
472478
if [[ "$name" == "$base_name" ]] || [[ "$name" == "main" ]]; then

0 commit comments

Comments
 (0)