Repository navigation
feat: Group Herdr workspaces by repository and let Herdr create worktrees - #113
Conversation
Workspaces that lazyworktree opened in Herdr used to sit loose in the Herdr sidebar, so a repository with several worktrees turned into a long flat list that was hard to scan. Each worktree workspace is now opened the same way Herdr's own worktree picker opens it, which makes it appear nested under its repository. Herdr opens the repository's main workspace alongside it when that one is not already open. Lazyworktree now also recognises a workspace by the folder it was opened in, not only by the tag it adds itself. A workspace opened from Herdr's own picker is therefore reused, shown in the command palette and replaced like any other, and workspaces are still found after a Herdr restart wipes the tags. When grouping is not possible, for instance with a bare repository or an older Herdr, a normal workspace is created as before. A new worktree_group option on the herdr block, on by default, lets people turn the grouping off.
Deleting a worktree used to leave its Herdr workspaces behind. They kept pointing at a folder that no longer existed, and any programme running in them carried on until someone closed the workspace by hand. Removing a worktree now also closes its Herdr workspaces, in every running Herdr session. This covers deleting from the interface, the merged worktree prune, and the delete and cleanup commands. The workspace that lazyworktree itself is running in is never closed, and a worktree that git failed to remove keeps its workspaces. Problems while closing are only reported as warnings, because the worktree is already gone at that point.
PR Summary by QodoGroup Herdr workspaces and optionally create worktrees through Herdr
AI Description
Diagram
High-Level Assessment
Files changed (33)
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
🔵 Needs a closer look
One or more reviewer sessions failed, leaving insufficient evidence to complete the approval-readiness review.
No open issues 🎉
What changed in this PR
This PR extends LazyWorktree’s Herdr integration to group workspaces by repository, optionally delegate worktree creation to Herdr, and close associated workspaces after deletion.
Changes:
- Opens grouped workspaces and recognises existing ones by checkout path as well as tags.
- Adds opt-in Herdr creation with Git fallback, post-init layouts, cancellation handling, and background focus control.
- Connects workspace cleanup to deletion flows and adds tests, configuration, and documentation.
Tests were not run in this review environment.
| File | Description |
|---|---|
lazyworktree.1 |
Documents grouping, creation options, and cleanup behaviour. |
internal/multiplexer/herdr.go |
Adds grouped opening, checkout matching, and cross-session cleanup. |
internal/multiplexer/herdr_test.go |
Tests grouping, reuse, fallback, and cleanup. |
internal/multiplexer/herdr_create.go |
Implements Herdr creation, Git fallback, and layout finalisation. |
internal/multiplexer/herdr_create_test.go |
Tests creation, recovery, rollback, layouts, and focus control. |
internal/models/models.go |
Adds the worktree creation request model. |
internal/git/worktree_hook.go |
Defines lifecycle hooks and parses supported worktree commands. |
internal/git/worktree_hook_test.go |
Tests command parsing and hook routing. |
internal/git/service.go |
Routes worktree operations through installed hooks. |
internal/config/config.go |
Adds creation settings, overrides, and default grouping. |
internal/config/config_herdr.go |
Parses grouping and resolves creation layout bindings. |
internal/config/config_herdr_test.go |
Tests grouping defaults, layout resolution, and overrides. |
internal/cli/operations.go |
Integrates deletion cleanup and post-init finalisation. |
internal/cli/operations_test.go |
Tests CLI finalisation and setup abandonment. |
internal/cli/cleanup.go |
Closes workspaces after successful cleanup removal. |
internal/bootstrap/commands.go |
Enables CLI creation hooks and grouped workspace opening. |
internal/bootstrap/bootstrap.go |
Prevents workspace focus when output selection is enabled. |
internal/app/worktree_operations.go |
Routes creation through setup handling and adds deletion cleanup. |
internal/app/screen/trust.go |
Supports a custom cancellation label. |
internal/app/screen/help.go |
Explains new Herdr options and Cancel Setup. |
internal/app/herdr.go |
Integrates grouped opening, palette matching, and cleanup. |
internal/app/herdr_test.go |
Tests grouped opening and repository workspace filtering. |
internal/app/base_selection.go |
Sends creation setup requests to the update loop. |
internal/app/base_selection_test.go |
Adapts tests to deferred setup handling. |
internal/app/app.go |
Installs the Herdr creator and handles setup messages. |
internal/app/app_helpers.go |
Adds background-only workspace focus control. |
internal/app/app_git.go |
Coordinates trust decisions, init commands, and finalisation. |
internal/app/app_git_test.go |
Tests setup ordering and trust prompt choices. |
hack/docsync/main.go |
Adds new options to generated configuration metadata. |
docs/guides/multiplexer-integration.md |
Explains grouping, creation, layouts, and lifecycle behaviour. |
docs/custom-commands.md |
Documents the grouping option. |
docs/configuration/reference.md |
Adds generated entries for creation settings. |
docs/configuration.md |
Summarises the new creation options. |
Review effort: Balanced
People who live in Herdr had to create a worktree in lazyworktree and then open a workspace for it as a separate step. A new option, use_herdr_for_workspace_create, hands the creation over to Herdr, so every new worktree arrives as a workspace already grouped under its repository. It is off by default and covers every way of creating a worktree: the create command, the interface, and the shell helpers. A second option, herdr_workspace_create_layout, names a custom command whose herdr block decides which tabs the new workspace gets. Lazyworktree still prepares the branch itself, so branch tracking and pull request upstreams behave as before, and anything Herdr cannot do, such as checking out a bare commit or tag, is done with git first. If Herdr fails, the worktree is created with git instead, and a branch Herdr left behind is removed only when lazyworktree created it. The layout is applied after the setup commands from the .wt file have run. When those commands fail and the worktree is rolled back, its workspace is closed too. On the trust prompt shown for any new worktree, the cancel button now reads Cancel Setup, because the worktree already exists: it is kept, without its commands or its layout. New workspaces are not focused when lazyworktree was started by a shell helper, so it stays in front until the user leaves it. Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
Cleanup also removes leftover worktree folders that git no longer knows about. Those folders could still have a Herdr workspace open on them, and it stayed behind after the folder was gone, unlike the workspaces of regular worktrees. Removing such a folder, from the cleanup command or from the prune in the interface, now closes its Herdr workspaces too.
The worktree operations, lifecycle and command palette pages did not yet mention the new Herdr behaviour. They now explain that deleting a worktree closes its Herdr workspaces, how to let Herdr create worktrees, that workspaces opened from Herdr's own picker show up in the palette, and that the trust prompt for a new worktree offers Cancel Setup, which keeps the worktree but skips its commands.
6cc49a5 to
5a96130
Compare

Three changes to how lazyworktree works with Herdr workspaces.
Grouped workspaces
herdr worktree open, the same path Herdr's own picker uses, so each one appears nested under its repository in the sidebar.on_exists: kill, and workspaces are still found after a Herdr restart drops the tags.worktree_group: falseon theherdrblock turns grouping off.Closing workspaces on delete
lazyworktree delete,lazyworktree cleanup) closes its Herdr workspaces in every running Herdr session.git worktree removekeeps its workspaces.Herdr creates the worktree (opt-in)
flowchart TD A[New worktree requested] --> B{use_herdr_for_workspace_create} B -- off --> G[git worktree add] B -- on --> C[lazyworktree prepares the branch] C --> D[herdr worktree create] D -- fails --> G D -- ok --> E[Run .wt init commands] G --> E E -- succeed --> F[Apply layout from herdr_workspace_create_layout] E -- fail, worktree removed --> X[Close the new workspace]--output-selectionnever focuses new workspaces, so the helper can stillcdonce you leave.Docs, the man page, the help screen and the generated config reference cover the new options.