Skip to content

fix: resolve_target fallback via git worktree list for external worktrees#128

Merged
helizaga merged 1 commit intomainfrom
fix/resolve-target-fallback-127
Feb 17, 2026
Merged

fix: resolve_target fallback via git worktree list for external worktrees#128
helizaga merged 1 commit intomainfrom
fix/resolve-target-fallback-127

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Feb 17, 2026

Summary

  • Adds a git worktree list --porcelain fallback as the last step in resolve_target() before returning "not found"
  • Catches worktrees created outside the gtr-managed directory (e.g. via raw git worktree add /some/other/path -b feature) that the existing directory scan cannot find
  • Only runs when all existing fast paths fail — zero performance impact on the happy path

Note: Issue #127 was closed as already fixed by #123/#126 (discover_repo_root fix). This PR addresses a separate gap where resolve_target couldn't find worktrees stored outside the gtr-managed worktrees directory.

Test plan

  • New BATS test: externally-created worktree found via porcelain fallback
  • Full test suite passes (271 tests)
  • Manual verification: git worktree add /tmp/ext -b ext-branchgit gtr go ext-branch succeeds
  • Manual verification: without fix, same scenario fails with "Worktree not found"

Summary by CodeRabbit

  • Bug Fixes
    • Improved worktree resolution to locate externally-created worktrees when initial lookup fails, enhancing fallback behavior and error handling.
  • Tests
    • Added coverage validating the fallback lookup for external worktrees and the reported worktree attributes.

@helizaga helizaga requested a review from NatoBoram as a code owner February 17, 2026 19:36
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a last-resort lookup in resolve_target that queries git worktree list --porcelain, parses entries to match a branch identifier, and emits a tab-separated line (is_main, path, branch) when found; preserves existing control flow if no match.

Changes

Cohort / File(s) Summary
Core fallback logic
lib/core.sh
Adds a porcelain-driven fallback in resolve_target: runs git worktree list --porcelain, iterates/parses entries to find a branch match, prints TSV (is_main<TAB>path<TAB>branch) and returns success; unchanged behavior if still not found.
Test coverage
tests/core_resolve_target.bats
Adds a test that creates an external worktree and asserts resolve_target returns is_main=0, a path ending with the external suffix, and the expected branch via the porcelain fallback.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Caller
participant resolve_target
participant GitCLI
participant Filesystem
Caller->>resolve_target: request resolution for
resolve_target->>Filesystem: check managed worktrees directory
alt found in managed directory
Filesystem-->>resolve_target: match (is_main/path/branch)
resolve_target-->>Caller: return TSV match
else not found
resolve_target->>GitCLI: git worktree list --porcelain
GitCLI-->>resolve_target: porcelain entries
resolve_target->>resolve_target: parse entries, match branch
alt match found in porcelain
resolve_target-->>Caller: return TSV (is_main/path/branch)
else no match
resolve_target-->>Caller: error "Worktree not found"
end
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
A branch once hidden, now I trot,
Through porcelain lines I trace the spot.
Main or linked, I sniff the trail,
A hop, a find — no worktree fails. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a fallback mechanism in resolve_target using git worktree list --porcelain to find worktrees.
Linked Issues check ✅ Passed The PR implements the core requirement from #127: resolve_target now searches for worktrees outside the managed directory via git worktree list --porcelain, enabling it to find branches in the main working tree.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objective: lib/core.sh adds the fallback lookup logic, and tests/core_resolve_target.bats adds corresponding test coverage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/resolve-target-fallback-127

Comment @coderabbitai help to get the list of available commands and usage tips.

…rees

Add a git worktree list --porcelain fallback as last resort in
resolve_target() before returning "not found". This catches worktrees
created outside the gtr-managed directory (e.g. via raw git worktree
add) that the directory scan cannot find.

Only runs when all fast-path checks fail, so zero performance impact
on the happy path.
@helizaga helizaga force-pushed the fix/resolve-target-fallback-127 branch from 0736f04 to d4cfdfa Compare February 17, 2026 19:48
@helizaga helizaga changed the title fix: resolve_target fallback via git worktree list (#127) fix: resolve_target fallback via git worktree list for external worktrees Feb 17, 2026
@helizaga helizaga merged commit 4556a5e into main Feb 17, 2026
3 of 4 checks passed
@helizaga helizaga deleted the fix/resolve-target-fallback-127 branch February 17, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments