Skip to content

Use the repository's worktree directory when Herdr does not name it - #602

Open
thiblahute wants to merge 1 commit into
powerfooI:mainfrom
thiblahute:upstream/worktree-location-default
Open

thiblahute wants to merge 1 commit into
powerfooI:mainfrom
thiblahute:upstream/worktree-location-default

Conversation

@thiblahute

Copy link
Copy Markdown
Collaborator

Summary

Create a worktree in the repository's configured worktree directory even when Herdr does not say which repository the source workspace belongs to. A follow-up to #550.

Why

Herdr's workspace.get does not always carry worktree.repo_key: a workspace opened outside a checkout, or one Herdr has not inspected yet, has none. Worktree creation then looked up the repository's settings under the source checkout's path, missed the worktree directory (and command) set for the repository, and fell back to Herdr's default ~/.herdr/worktrees/<checkout name>/<branch>.

The settings dialogs had the same gap: the Worktree Location dialog and the worktree hooks settings showed and saved the checkout path's settings, and Ranger confirmed a worktree command under that key, so creation then refused it as changed.

What changed

  • server/src/worktree/create.ts: resolveRepoSettingsKey names the repository when Herdr does not, by asking git for the checkout's common directory (git rev-parse --path-format=absolute --git-common-dir, over SSH for remote hosts), the key Herdr uses. Every checkout of a repository, the main one or a linked worktree, then shares its settings. Settings already saved under a checkout path keep applying. The default checkout path takes the repository's name from that directory too.
  • server/src/bridge/settings-rpc.ts: the worktree location and worktree hooks RPCs use the same key, so the dialogs show and save what creation applies.
  • server/src/assistant/actions.ts: Ranger's worktree confirmation uses the same key.
  • docs/DEPLOYMENT.md: the worktree location is shared by every checkout of the repository.

Verification

  • bun test server/src/worktree/create.test.ts server/src/assistant/actions.test.ts server/src/bridge/settings-rpc.test.ts: 152 pass. New tests: a workspace Herdr reports no repository for uses its repository's directory; a worktree command defaults under the repository's name, not the linked checkout's; settings saved under the checkout path still apply; a repository Herdr reports is not asked of git; the settings RPC and Ranger's confirmation use the repository's key. Four of them fail on main.
  • bun run format:check, bun run lint (only the existing TerminalView.tsx warning), bun run typecheck:bun, bun run test:quick with an isolated HOME/TMPDIR.

Manual checks

  • Set a worktree location on a repository, then create a worktree from a linked worktree of it: the new checkout lands in that location.
  • Open the Worktree Location dialog from a linked worktree: it shows the repository's location, and a change there applies to the main checkout too.

Herdr's workspace.get does not always describe the workspace's repository
(no worktree.repo_key), for a workspace opened outside a checkout or one
it has not inspected yet. Worktree creation then looked up the
repository's settings under the source checkout's path, missed the
configured worktree directory and fell back to Herdr's default
~/.herdr/worktrees/<checkout name>/<branch>.

Ask git for the root's common directory in that case, the key Herdr
uses, so that a worktree created from any checkout of a repository, the
main one or a linked worktree, lands in its worktree directory and runs
its worktree command. Settings saved under a checkout path keep applying.

Resolve that key in one place, resolveRepoSettingsKey, and use it for
creation, Ranger's confirmation and the settings dialogs: the Worktree
Location dialog and the worktree hooks settings showed and saved the
checkout path's settings, and Ranger confirmed the command under that
key, so creation refused it as changed.
@github-actions github-actions Bot added the enhancement New feature or request label Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant