Skip to content

[Worktree] Find a worktree again after its folder was moved (part 5) - #731

Merged
goneng merged 1 commit into
masterfrom
repair-worktrees
Sep 27, 2026
Merged

goneng merged 1 commit into
masterfrom
repair-worktrees

Conversation

@goneng

@goneng goneng commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Slice 5 of #675: find a worktree again after its folder was moved, the way Tower offers to repair one,
instead of offering only to prune it.
(It builds on #727 (slice 4) and targets its branch so the diff shows this slice alone; merge #723 and #727 first.)

Changes

  • While a worktree's folder is missing, Locate Worktree Folder... takes the place of Reveal Worktree in Finder, which had nothing to reveal, the same way Lock and Unlock trade places. The sidebar row and the branch label in the history list stay identical:

    Open Worktree of Branch "X"
    Copy name "X"
    ----
    Locate Worktree Folder...   (Reveal Worktree in Finder while the folder is there)
    Lock Worktree... / Unlock Worktree
    ----
    (branch items, unchanged)
    
  • The missing-folder sheet (double-clicking a dimmed worktree) gains a Locate Folder... button and a sentence saying what it is for.

  • Locating opens a folder panel at the worktree's old location and runs git worktree repair <folder>. It works on a locked worktree too, which stays locked.

  • A wrong folder is caught: git's own error is shown for a folder that is no worktree. Two cases git lets through are checked by GitX: a folder that already belongs to a worktree is refused before git runs, and when the chosen folder is another moved worktree's (git quietly repairs that one and exits 0), GitX reports that the worktree asked about is still missing.

Screenshots

Missing Worktree - Grayed-out and "Prunable":

image

Missing Worktree - Can Prune:

image

Missing Worktree - Can Locate:

image

Older git

git worktree repair arrived in git 2.29. Following the plan agreed on the issue (comment) and the version check #723 adds, Locate Worktree Folder... is shown disabled before 2.29 with a tooltip naming the version needed and the one found, and the sheet offers no Locate Folder... button.

Repairing after the main repository's folder moves (git worktree repair with no path) is not part of this slice.

Test plan

  • make unit-test: 289 tests, 10 of them new: the 2.28.1/2.29 boundary; repairing a moved worktree and a moved locked one against a real repository; refusing another worktree's folder, a plain folder, and another moved worktree's folder; the menu swap in both menus and on an older git; and the sheet's buttons.
  • In the Debug build, on a scratch repository with a worktree whose folder was moved: the sheet's text and buttons, Locate Folder... opening the panel, choosing the moved folder (git worktree list then shows the new path and GitX's list follows), the menu action reaching the window controller, and choosing the main worktree's folder refused with its reason.

@goneng
goneng force-pushed the add-and-remove-worktrees branch from 9e93e8f to 9b960de Compare September 25, 2026 21:54
@goneng goneng changed the title [Worktree] Find a worktree again after its folder was moved [Worktree] Find a worktree again after its folder was moved (part 5) Sep 26, 2026
@goneng
goneng force-pushed the add-and-remove-worktrees branch from 9b960de to 290c450 Compare September 26, 2026 07:59
@goneng
goneng force-pushed the repair-worktrees branch 2 times, most recently from 1804a03 to 4662c74 Compare September 26, 2026 10:33
@goneng
goneng force-pushed the add-and-remove-worktrees branch 2 times, most recently from b924929 to f48323c Compare September 26, 2026 18:59
@goneng
goneng force-pushed the add-and-remove-worktrees branch from f48323c to 8150610 Compare September 26, 2026 20:59
Base automatically changed from add-and-remove-worktrees to master September 27, 2026 04:54
Let a worktree whose folder went missing be pointed at where the folder
went, so git connects it again instead of offering only to prune it.

- Offer "Locate Worktree Folder..." in place of Reveal while a
  worktree's folder is missing, and a "Locate Folder..." button on the
  missing-folder sheet; both run `git worktree repair` (git 2.29)
- Refuse a folder that already belongs to a worktree, and report it
  when git connected the chosen folder to some other worktree
- Disable the item with the version it needs on an older git
@goneng
goneng marked this pull request as ready for review September 27, 2026 06:35
@hannesa2

Copy link
Copy Markdown
Contributor

Screenshot differs: emulatorApi=arm64 with 1 screenshot(s)

setpoint (old) | diff | actual screenshot (new)

commit-context-menu.pngscreenshot

@hannesa2

Copy link
Copy Markdown
Contributor

Following #675 means, that this is probably the last one for worktree. Does it make sense, after this merge, to create a new worktree-release ?

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.

Copilot review overview

🔵 Needs a closer look

Address the main-thread blocking and repair-verification issues, plus the missing-path directory check.

Review effort: Lite
Findings: None

What changed in this PR

Adds support for locating moved worktree folders via git worktree repair, with version gating, validation, UI actions, and tests.

Changes:

  • Adds worktree repair and verification logic.
  • Adds Locate Folder actions and missing-folder UI.
  • Adds Git version and repair scenario tests.
File Description
GitXTests/​PBGitWorktreeManagementTests.m Tests repair behavior and UI flows.
GitXTests/​PBGitBinaryVersionTests.m Tests the Git version boundary.
Classes/​git/​PBGitRepository.m Implements repair and validation.
Classes/​git/​PBGitRepository.h Exposes the repair API.
Classes/​git/​PBGitBinary.h Defines the repair version requirement.
Classes/​Controllers/​PBGitWindowController.m Adds folder-selection and repair UI.
Classes/​Controllers/​PBGitWindowController.h Declares the locate action.
Classes/​Controllers/​PBGitHistoryController.m Switches menu actions for missing folders.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@goneng

goneng commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Following #675 means, that this is probably the last one for worktree. Does it make sense, after this merge, to create a new worktree-release ?

Yes, I think so. We've also improved support for dark/light mode and solved quite a few annoying bugs, so feels like it deserves a release.

@tagliala

tagliala commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the worktree support, really appreciate these improvements to gitx

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants