Apply worktree layouts on worktree.opened too (fixes intermittent no-op)#25
Merged
Conversation
herdr fires worktree.created only when it creates a brand-new worktree; opening an existing worktree into a workspace (e.g. the right-click dialog for a branch that already has a worktree) fires worktree.opened instead. We only subscribed to created, so opening an existing worktree silently skipped the layout — which read as the feature working intermittently. Subscribe to both events, sharing one handler (renamed on-worktree-created -> on-worktree, runOnWorktreeCreated -> runOnWorktreeEvent). Add an idempotency guard that skips a workspace already holding more than one pane, so a layout never applies twice even if both events fire for the same workspace or herdr reopens an already-populated one. Verified live against herdr 0.7.0: create fires exactly one event and applies once; open now fires and applies; back-to-back open of a populated workspace is skipped. Also fixes a stale herdr-plugin.toml comment that still referenced the removed enabled toggle, and documents that worktrees must be created/opened through herdr (not plain git) for the events to fire.
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 bug
Worktree auto-layout worked intermittently — sometimes a new worktree got its tabs, sometimes nothing happened.
Root cause: herdr has two worktree events, and we only subscribed to one.
worktree.created— fired when herdr creates a brand-new worktree.worktree.opened— fired when herdr opens an existing worktree into a workspace (e.g. the right-click dialog for a branch that already has a worktree).We only listened for
worktree.created, so opening an existing worktree silently skipped the layout — no handler invocation at all in the plugin log.The fix
worktree.createdandworktree.opened, sharing one handler (on-worktree-created→on-worktree,runOnWorktreeCreated→runOnWorktreeEvent).herdr-plugin.tomlcomment that still referenced the removedenabledtoggle.git worktree add/ lazygit don't fire herdr events).Verified live against herdr 0.7.0
Using
herdr plugin linkof this branch:worktree create(new)worktree.created×1worktree open(existing)worktree.opened×1opened(no double-apply)go build,go test, andgo vetall pass.