Skip to content

fix(session): resolve --repo selector to repo root#424

Merged
benvinegar merged 1 commit into
modem-dev:mainfrom
franky47:fix/423-sessions-repo-subdir
Jun 13, 2026
Merged

fix(session): resolve --repo selector to repo root#424
benvinegar merged 1 commit into
modem-dev:mainfrom
franky47:fix/423-sessions-repo-subdir

Conversation

@franky47

Copy link
Copy Markdown
Contributor

Sessions register under their git toplevel, so a --repo selector run from a subdirectory never matched.

Walk up to the containing repo root (and canonicalize through symlinks) so queries target the session from anywhere in the tree.

Closes #423.

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes hunk session ... --repo <path> selectors failing when the path is a subdirectory or sits behind a symlink. Sessions register under their VCS toplevel (canonicalized via realpathSync), so a --repo path pointing anywhere inside the tree never matched the registered root.

  • Introduces resolveRepoSelectorRoot, which calls detectVcs to walk up from the given path to the VCS root and then canonicalizes through symlinks with realpathSync.native, mirroring how the session's own repoRoot is stored.
  • Both resolveExplicitSessionSelector (used by session get/review) and resolveReloadSelector now use this helper, replacing the old bare resolve() calls.
  • Three new tests cover subdirectory resolution, symlink canonicalization, and the reload code path; the CHANGELOG entry is properly added.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to path canonicalization before session lookup and cannot affect session data or VCS operations.

The new helper is small, well-commented, and has a clean fallback. detectVcs is synchronous and only returns a repoRoot when the directory is confirmed to exist on disk, so the subsequent realpathSync.native call is safe. Three targeted tests cover the exact scenarios described in the bug report. No observable behavior change for callers using already-canonical repo roots.

No files require special attention.

Important Files Changed

Filename Overview
src/core/cli.ts Adds resolveRepoSelectorRoot that walks up to the VCS root via detectVcs then canonicalizes with realpathSync.native; replaces bare resolve() in both selector helpers. Logic is sound and fallback behavior (non-VCS paths) is preserved.
src/core/cli.test.ts Three new tests cover subdirectory resolution (get), symlink canonicalization (get), and subdirectory resolution for reload. Tests are well-structured with proper cleanup and a platform-safe skip for symlinks on Windows.
CHANGELOG.md Adds a clear, user-facing fix entry under the unreleased section describing the subdirectory/symlink matching improvement.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["--repo <path> provided"] --> B["resolve(repoPath)\n(absolute path, no symlink resolution)"]
    B --> C["detectVcs(resolved)\n(walk up looking for .git / .jj / .sl)"]
    C -->|"VCS root found"| D["realpathSync.native(repoRoot)\n(canonicalize through symlinks)"]
    C -->|"No VCS root"| E["return resolved\n(original absolute path, no canonicalization)"]
    D --> F["selector: { repoRoot: canonicalRoot }"]
    E --> F
    F --> G["Match against registered session\n(session repoRoot is also realpath-canonical)"]
Loading

Reviews (1): Last reviewed commit: "fix(session): resolve --repo selector to..." | Re-trigger Greptile

@benvinegar benvinegar force-pushed the fix/423-sessions-repo-subdir branch from c0b46a5 to 3d06996 Compare June 13, 2026 13:36
Sessions register under their git toplevel, so a --repo selector run
from a subdirectory never matched.

Walk up to the containing repo root (and canonicalize
through symlinks) so queries target the session from anywhere
in the tree.

Closes modem-dev#423.
@benvinegar benvinegar force-pushed the fix/423-sessions-repo-subdir branch from 3d06996 to 4004d08 Compare June 13, 2026 13:42
@benvinegar benvinegar merged commit 68f3403 into modem-dev:main Jun 13, 2026
7 checks passed
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.

hunk session --repo . fails from a subdirectory of the repo

2 participants