Skip to content

fix: resolve worktree root before removal in monorepos#61

Merged
matej21 merged 2 commits intocontember:mainfrom
JanTvrdik:fix/close-worktree-monorepo
Mar 27, 2026
Merged

fix: resolve worktree root before removal in monorepos#61
matej21 merged 2 commits intocontember:mainfrom
JanTvrdik:fix/close-worktree-monorepo

Conversation

@JanTvrdik
Copy link
Copy Markdown
Contributor

Summary

  • In monorepo setups, closing a worktree fails because project.path points to a subdirectory inside the worktree (e.g. /repo-wt-branch/app), not the worktree root
  • Use get_repo_root() (git rev-parse --show-toplevel) to resolve the actual worktree root before passing it to git worktree remove
  • Falls back to the project path for non-monorepo setups

Closes #60

Test plan

  • Manual: in a monorepo, create a worktree for a subdirectory project, then close it — verify it succeeds
  • Manual: in a non-monorepo, create and close a worktree — verify it still works

Co-Authored-By: Claude Code

In monorepo setups the project path points to a subdirectory inside the
worktree checkout (e.g. /repo-wt-branch/app), causing `git worktree remove`
to fail with "is not a working tree". Use `get_repo_root()` to resolve the
actual worktree root before passing it to the remove command.

Closes contember#60

Co-Authored-By: Claude Code
Copilot AI review requested due to automatic review settings March 26, 2026 12:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes worktree close failures in monorepo setups by ensuring git worktree remove is called with the actual worktree root (instead of a subdirectory project path).

Changes:

  • Resolve the git repo/worktree root via okena_git::get_repo_root() before determining branch and removing the worktree.
  • Fall back to project.path when the repo root cannot be resolved.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/okena-workspace/src/actions/project.rs
Verify that get_repo_root correctly resolves the worktree root (not a
subdirectory) when called from a nested path inside a worktree. This
covers the monorepo worktree removal fix.

Co-Authored-By: Claude Code
@matej21 matej21 merged commit a8b43c0 into contember:main Mar 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Close worktree fails for monorepos

3 participants