Skip to content

Fix renaming worktrees on Windows - #23056

Merged
niik merged 1 commit into
developmentfrom
niik-fix-worktree-rename-windows
Oct 22, 2026
Merged

niik merged 1 commit into
developmentfrom
niik-fix-worktree-rename-windows

Conversation

@niik

@niik niik commented Oct 21, 2026

Copy link
Copy Markdown
Member

Description

Renaming a worktree is broken on Windows. It fails with:

fatal: failed to move '<old>' to '<new>': Permission denied

moveWorktree ran git worktree move <old> <new> with its working directory set to repository.path. AppStore._moveWorktree receives 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

moveWorktree now finds the main worktree with listWorktrees (the entry with type === 'main') and runs git worktree move from 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 that git worktree move accepts --.

Tests

The new file app/test/unit/git/worktree-move-test.ts wraps dugite's exec using mock.module. The real git still runs, but the test records each call's working directory and asserts that git worktree move never 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:

  • renaming the linked worktree the repository points to (the Windows bug)
  • renaming another linked worktree from the main worktree (the existing behavior)
  • renaming a linked worktree from a sibling linked worktree

Each test also checks the result on disk and in git worktree list.

Follow-up

On niik-repository-account-association (#23020), two rename tests in app/test/unit/stores/app-store-add-accounts-test.ts are 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

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]>
@niik
niik requested a review from a team as a code owner October 21, 2026 15:21
@niik
niik requested review from BagToad and a balanced review from Copilot October 21, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 move from 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

@niik
niik merged commit aa9bd3e into development Oct 22, 2026
18 checks passed
@niik
niik deleted the niik-fix-worktree-rename-windows branch October 22, 2026 07:03
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]>
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.

3 participants