Repository navigation
Conversation
…n checkout Git refuses to check out a branch that is already checked out in another worktree. GitUp now shows which branches are in that state and explains what to do instead of failing with a bare error. Added -[GCRepository lookupWorktreePathsForCheckedOutBranches:] which maps the branches checked out in other worktrees, the main one or linked ones, to their working directories. Worktrees with a detached HEAD or a missing directory are skipped. The result is cached in GCHistoryLocalBranch.worktreePath and included in the history references checksum, and GCLiveRepository now also watches ".git/worktrees/", so the graph updates when a worktree is added, removed or switched to another branch. The graph shows a "⧉ worktree: <folder>" line under the title of such a branch and a ⧉ marker next to its name in node labels and in the selected commit tooltip. Checking out such a branch shows an alert with Open Worktree, Show in Finder and Cancel instead of the "already checked out in another worktree" error.
[Medium impact] The PR appears safe to merge; the previous watch gap is addressed and no new actionable issues were found.
|
When GitUp opens a linked worktree, its git directory is ".git/worktrees/<name>/", so the HEAD of the main worktree and the git directories of the other linked worktrees were not watched and the worktree markers stayed stale until the next history update. GCLiveRepository now also watches the common git directory of a linked worktree and reloads the history when its root or "worktrees/" changes. Other changes in the common git directory are still ignored.
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.
Problem
Git doesn't allow checking out a branch that is already checked out in another worktree. Since #2803 GitUp no longer leaves the working directory dirty in that case, but you only get a bare "Branch '…' is already checked out in another worktree" error, and the graph gives no hint beforehand about which branches are taken.
Changes
⧉ worktree: <folder>line under its title, and a ⧉ marker after its name in node labels and in the selected commit tooltip. Detached HEADs are not marked, since a commit can be checked out in any number of worktrees.-[GCRepository lookupWorktreePathsForCheckedOutBranches:]. The result is cached asGCHistoryLocalBranch.worktreePathand included in the history references checksum, andGCLiveRepositoryalso watches.git/worktrees/, so the marker updates when a worktree is added, removed or switched to another branch.Screenshots
Trade-off
The extra line makes the title block taller, so the existing overlap avoidance in
_DrawBranchTitlemay truncate a long title in the column to the left (marked in orange in the first screenshot). The same already happens when a tip has tags or several branches.Tests
GCBranch-Tests.m: a branch checked out in a linked worktree is mapped to its directory; seen from a linked worktree, the branch of the main worktree is listed while its own branch is not; worktrees with a detached HEAD or a deleted directory are skipped.GCHistory-Tests.m: the history branch carries the worktree path.GCLiveRepository-Tests.m: an open repository drops the marker when the linked worktree is removed.I AGREE TO THE GITUP CONTRIBUTOR LICENSE AGREEMENT