File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ cmd_copy() {
6262 # Build target list for --all mode
6363 if [ " $all_mode " -eq 1 ]; then
6464 local all_branches
65- all_branches=$( list_worktree_branches " $base_dir " " $prefix " )
65+ all_branches=$( list_worktree_branches " $base_dir " " $prefix " " $repo_root " )
6666 if [ -z " $all_branches " ]; then
6767 log_error " No worktrees found"
6868 exit 1
Original file line number Diff line number Diff line change @@ -214,8 +214,11 @@ _emit_worktree_record() {
214214
215215 [ -z " $wt_path " ] && return 0
216216
217- local is_main=0 branch=" $wt_branch " status
218- [ " $wt_path " = " $repo_root " ] && is_main=1
217+ local is_main=0 branch=" $wt_branch " status wt_path_canonical
218+ wt_path_canonical=$( canonicalize_path " $wt_path " || printf " %s" " $wt_path " )
219+ if [ " $wt_path " = " $repo_root " ] || [ " $wt_path_canonical " = " $repo_root " ]; then
220+ is_main=1
221+ fi
219222 [ -z " $branch " ] && branch=" (detached)"
220223 status=$( _worktree_record_status " $wt_detached " " $wt_locked " " $wt_prunable " )
221224
@@ -660,13 +663,15 @@ resolve_repo_context() {
660663}
661664
662665# List all worktree branch names (excluding main repo)
663- # Usage: list_worktree_branches base_dir prefix
666+ # Usage: list_worktree_branches base_dir prefix [repo_root]
664667# Returns: newline-separated list of branch names
665668list_worktree_branches () {
666669 local base_dir=" $1 "
667670 local prefix=" $2 "
668- local repo_root
669- repo_root=$( _resolve_main_repo_root) || return 0
671+ local repo_root=" ${3:- } "
672+ if [ -z " $repo_root " ]; then
673+ repo_root=$( _resolve_main_repo_root) || return 0
674+ fi
670675
671676 # base_dir and prefix are kept for the public helper contract. Worktree
672677 # discovery itself comes from Git's registry so nested registered worktrees
Original file line number Diff line number Diff line change @@ -50,6 +50,17 @@ teardown() {
5050 [[ " $branches " != * " (detached)" * ]]
5151}
5252
53+ @test " list_worktree_branches uses explicit repo root outside repo" {
54+ local base_dir=" ${TEST_REPO} -worktrees"
55+ create_worktree " $base_dir " " " " outside-context" " HEAD" " none" " 1" " 0" " " " " > /dev/null
56+ cd /tmp || false
57+
58+ local branches
59+ branches=$( list_worktree_branches " $base_dir " " " " $TEST_REPO " )
60+
61+ [[ " $branches " == * " outside-context" * ]]
62+ }
63+
5364@test " resolve_target finds worktree by branch name" {
5465 local default_branch
5566 default_branch=$( git rev-parse --abbrev-ref HEAD)
You can’t perform that action at this time.
0 commit comments