Skip to content

fix(pool): cwdInWorktree accepts dot-prefixed subdirectories#33

Open
e-jung wants to merge 1 commit into
kunchenguid:mainfrom
e-jung:fix/cwdinworktree-dot-subdirs
Open

fix(pool): cwdInWorktree accepts dot-prefixed subdirectories#33
e-jung wants to merge 1 commit into
kunchenguid:mainfrom
e-jung:fix/cwdinworktree-dot-subdirs

Conversation

@e-jung

@e-jung e-jung commented Jun 22, 2026

Copy link
Copy Markdown

Intent

treehouse status fails to recognize the user as "here" when their cwd is inside a dot-prefixed subdirectory of a worktree (e.g. <worktree>/.venv, <worktree>/.cache, <worktree>/.git-hooks).

The cwdInWorktree predicate rejected any relative path whose first character is a dot, so .venv/bin (relative path .venv/bin) was treated as "not in the worktree", suppressing the "you're here" marker on the owning worktree in status output.

This is a status-display-only bug — no data loss, no acquisition/release behavior change. Very low risk.

Approach

The cwdInWorktree predicate ended with:

return rel == "." || !filepath.IsAbs(rel) && len(rel) >= 1 && rel[0] != '.'

The rel[0] != '.' check was meant to reject .. escapes but also rejected every dot-prefixed subdir (.venv, .cache, .git-hooks, ...). The correct, minimal predicate already exists in-repo at internal/process/detect.go:75:

rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))

Apply that same predicate in cwdInWorktree: the cwd is in the worktree when rel == "." (the root) or rel does not start with .. (does not escape the root). Dot-prefixed subdirectories like .venv/bin satisfy this and are now correctly recognized.

Scope

Two files, +46 / -1:

  • internal/pool/pool.gocwdInWorktree uses the same "does not escape via .." predicate as internal/process/detect.go; adds the strings import.
  • internal/pool/pool_test.gofirst test for cwdInWorktree, a table-driven TestCwdInWorktree covering: worktree root (.), regular subdir (src/foo), dot-prefixed subdirs (.venv/bin, .cache/tmp — the bug case), the worktree parent (..), and a sibling directory.

Risk

Very low. cwdInWorktree only drives the "you're here" (StatusHere) marker in status output — it is not on the acquisition, release, prune, or destroy paths. The new predicate matches the one already validated in internal/process/detect.go. No data-loss surface; no behavioral change beyond the status marker.

Verification

  • New TestCwdInWorktree passes on the fixed code.
  • Confirmed the test has teeth: against the old predicate, the two dot-prefixed subdirectory cases (/.venv/bin, /.cache/tmp) fail with = false, want true, while the root / regular-subdir / outside / sibling cases pass — exactly the regression the fix targets.
  • Full suite green: go test ./... (cmd, internal/config, internal/git, internal/hooks, internal/pool, internal/process, internal/updater).
  • go vet ./... clean; gofmt clean.
Regression test transcript (buggy vs fixed)
=== Against BUGGY predicate (rel[0] != '.') ===
--- PASS: TestCwdInWorktree/worktree_root
--- PASS: TestCwdInWorktree/regular_subdir
--- FAIL: TestCwdInWorktree/dot-prefixed_subdir_.venv/bin   (false, want true)
--- FAIL: TestCwdInWorktree/dot-prefixed_subdir_.cache/tmp  (false, want true)
--- PASS: TestCwdInWorktree/parent_of_worktree_(rel_starts_with_..)
--- PASS: TestCwdInWorktree/sibling_dir
FAIL

=== Against FIXED predicate ===
--- PASS: TestCwdInWorktree/worktree_root
--- PASS: TestCwdInWorktree/regular_subdir
--- PASS: TestCwdInWorktree/dot-prefixed_subdir_.venv/bin
--- PASS: TestCwdInWorktree/dot-prefixed_subdir_.cache/tmp
--- PASS: TestCwdInWorktree/parent_of_worktree_(rel_starts_with_..)
--- PASS: TestCwdInWorktree/sibling_dir
PASS

AI disclosure

Human-reviewed. The investigation (locating the predicate and its correct counterpart in internal/process/detect.go), the fix, and the regression test were produced autonomously and reviewed by a human operator before opening.

The cwdInWorktree predicate rejected any relative path starting with a
dot, so being inside a dot-prefixed subdirectory of a worktree (e.g.
.venv/bin, .cache/tmp, .git-hooks) was treated as "not here", causing
treehouse status to fail to mark the user as present in the worktree.

Replace the rel[0] != '.' check with the same "does not escape via .."
predicate already used by internal/process/detect.go: rel must be "."
or must not start with "..". This is a status-display-only regression,
so the impact is limited to the "you're here" marker.

Add the first test for cwdInWorktree as a table-driven test covering
the worktree root, regular subdirs, dot-prefixed subdirs (the bug
case), and paths outside the worktree.
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