Repository navigation
Fix renaming worktrees on Windows - #23056
Merged
Merged
Conversation
Renaming a worktree failed on Windows with "Permission denied" because git was run with the worktree being moved as its working directory, and Windows refuses to rename a directory that is a process's current directory. Resolve the main worktree via `git worktree list` and run the move from there instead, and separate the paths with `--`. Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The localized fix addresses the Windows restriction with regression coverage for all three caller contexts.
No open issues 🎉
What changed in this PR
Fixes worktree renaming on Windows by running Git outside the directory being moved.
Changes:
- Runs
git worktree movefrom the main worktree and separates paths from options with--. - Adds regression tests covering calls from the moved worktree, main worktree, and a sibling worktree.
| File | Description |
|---|---|
| app/test/unit/git/worktree-move-test.ts | Tests working-directory selection and rename results. |
| app/src/lib/git/worktree.ts | Runs worktree moves from the main worktree. |
Review effort: Balanced
sergiou87
approved these changes
Oct 22, 2026
niik
added a commit
that referenced
this pull request
Oct 22, 2026
The rename now runs from the main worktree (#23056). Co-authored-by: Copilot App <[email protected]>
MatDayProjects
pushed a commit
to Ding-Ding-Projects/desktop-material
that referenced
this pull request
Nov 10, 2026
…GitHub Desktop 3.6.8 Ports upstream desktop/desktop#23056 unchanged with its tests, which pass on Linux against the system Git. The Windows behaviour it fixes is not verified here. Refs #212. 由上游 3.6.8 搬過嚟:喺 Windows 改工作樹個名唔會再彈權限錯誤。測試喺 Linux 過咗,Windows 實際效果未驗證。 Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.
Description
Renaming a worktree is broken on Windows. It fails with:
moveWorktreerangit worktree move <old> <new>with its working directory set torepository.path.AppStore._moveWorktreereceives the currently selected repository, and the worktree being renamed is usually that same repository. As a result, git ran from inside the directory it was trying to move. Windows won't rename a directory that is any process's current working directory. macOS and Linux allow it, which is why the bug only shows up on Windows.Fix
moveWorktreenow finds the main worktree withlistWorktrees(the entry withtype === 'main') and runsgit worktree movefrom there. The main worktree can never be the one being moved, and it can't sit inside a linked worktree. The paths are now separated from options with--. I checked thatgit worktree moveaccepts--.Tests
The new file
app/test/unit/git/worktree-move-test.tswraps dugite'sexecusingmock.module. The real git still runs, but the test records each call's working directory and asserts thatgit worktree movenever runs from inside the worktree being moved. That makes the test catch the bug on macOS and Linux too. With the old implementation, the "repository is the worktree being moved" case fails on macOS.Cases covered:
Each test also checks the result on disk and in
git worktree list.Follow-up
On
niik-repository-account-association(#23020), two rename tests inapp/test/unit/stores/app-store-add-accounts-test.tsare skipped on Windows with{ skip: __WIN32__ }. Once this lands, those tests can be re-enabled.Release notes
Notes: [Fixed] Renaming a worktree no longer fails with "Permission denied" on Windows