File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -299,6 +299,24 @@ resolve_target() {
299299 done
300300 fi
301301
302+ # Last resort: ask git for all worktrees (catches non-gtr-managed worktrees)
303+ local wt_path wt_branch
304+ while IFS= read -r line; do
305+ case " $line " in
306+ " worktree " * ) wt_path=" ${line# worktree } " ;;
307+ " branch " * )
308+ wt_branch=" ${line# branch refs/ heads/ } "
309+ if [ " $wt_branch " = " $identifier " ]; then
310+ local is_main=0
311+ [ " $wt_path " = " $repo_root " ] && is_main=1
312+ printf " %s\t%s\t%s\n" " $is_main " " $wt_path " " $wt_branch "
313+ return 0
314+ fi
315+ ;;
316+ " " ) wt_path=" " ; wt_branch=" " ;;
317+ esac
318+ done < <( git -C " $repo_root " worktree list --porcelain 2> /dev/null)
319+
302320 log_error " Worktree not found for branch: $identifier "
303321 return 1
304322}
Original file line number Diff line number Diff line change @@ -81,6 +81,18 @@ teardown() {
8181 [ " $status " -eq 1 ]
8282}
8383
84+ # ── porcelain fallback ─────────────────────────────────────────────────────────
85+
86+ @test " resolve_target finds externally-created worktree via porcelain fallback" {
87+ # Create a worktree with raw git (outside gtr-managed directory)
88+ local ext_dir=" ${TEST_REPO} -external"
89+ git -C " $TEST_REPO " worktree add " $ext_dir " -b external-branch --quiet
90+ local result
91+ result=$( resolve_target " external-branch" " $TEST_REPO " " $TEST_WORKTREES_DIR " " " )
92+ # Assert: found with is_main=0, correct branch, path ends with expected suffix
93+ [[ " $result " == " 0" $' \t ' * " -external" $' \t ' " external-branch" ]]
94+ }
95+
8496# ── discover_repo_root from worktree ──────────────────────────────────────────
8597
8698@test " discover_repo_root returns main repo root when called from a worktree" {
You can’t perform that action at this time.
0 commit comments