feat: group session browser by git repo root (worktree-aware)#3737
Merged
Conversation
Adds pkg/gitroot to resolve any directory to its main repository root, handling linked worktrees via .git file metadata. The session browser's workspaceMatcher now normalises paths to their git root so subdirectories and worktrees of the same repo group together; the 'This workspace' header displays the repo root accordingly. Assisted-By: Claude
…ut, symlink fallback in header
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The new gitroot package and its integration into session_browser.go are well-implemented. The worktree-aware grouping logic is correct: .git pointer files are parsed, commondir is resolved for linked worktrees, file reads are bounded to 4 KiB, and symlinks are resolved before comparison. Test coverage is thorough across plain repos, subdirectories, worktrees, bare repos, submodules, and symlinked paths.
No bugs were found in the code introduced by this PR.
aheritier
approved these changes
Jul 18, 2026
aheritier
added a commit
that referenced
this pull request
Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The past-sessions dialog groups sessions under a "This workspace" header by comparing the current working directory against each session's recorded directory. This breaks with git worktrees: a session started from a worktree, a subdirectory, or the main checkout of the same repository all appear as separate workspaces, even though they share the same codebase.
The fix introduces
pkg/gitroot, a small package that resolves any directory to its canonical git repository root without shelling out. It walks up the directory tree looking for a.gitentry. When.gitis a file (a linked worktree), it reads thegitdir:pointer and then follows thecommondirfile to arrive at the main repository root. Bare-repo worktrees resolve to the bare repo directory; submodules are treated as independent roots. The session browser'sworkspaceMatchernow normalizes both the current directory and each stored session directory to their git root (with symlinks resolved first, and results cached), so all worktrees of the same repository fold under one header. The header itself displays the repository root path, consistent with the grouping key.A follow-up hardening pass bounds
.gitpointer andcommondirfile reads to 4 KiB, cleans the input path before walking, and adds a symlink-resolution fallback so the displayed header stays consistent even whenos.Getwdreturns a symlinked path. The package has thorough tests covering plain repos, subdirectories, linked worktrees with both relative and absolutecommondirpaths, bare-repo worktrees, submodules, dangling and oversized.gitpointers, and symlinked workspaces.