Skip to content

feat: group session browser by git repo root (worktree-aware)#3737

Merged
aheritier merged 2 commits into
docker:mainfrom
dgageot:session-browser-git-root
Jul 18, 2026
Merged

feat: group session browser by git repo root (worktree-aware)#3737
aheritier merged 2 commits into
docker:mainfrom
dgageot:session-browser-git-root

Conversation

@dgageot

@dgageot dgageot commented Jul 18, 2026

Copy link
Copy Markdown
Member

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 .git entry. When .git is a file (a linked worktree), it reads the gitdir: pointer and then follows the commondir file 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's workspaceMatcher now 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 .git pointer and commondir file reads to 4 KiB, cleans the input path before walking, and adds a symlink-resolution fallback so the displayed header stays consistent even when os.Getwd returns a symlinked path. The package has thorough tests covering plain repos, subdirectories, linked worktrees with both relative and absolute commondir paths, bare-repo worktrees, submodules, dangling and oversized .git pointers, and symlinked workspaces.

dgageot added 2 commits July 18, 2026 10:09
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
@dgageot
dgageot requested a review from a team as a code owner July 18, 2026 08:17

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 aheritier added area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 18, 2026
@aheritier
aheritier merged commit e8a5eb1 into docker:main Jul 18, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants