Repository navigation
Fix dragging a file to the Finder taking it out of the repository - #592
Merged
Merged
Conversation
goneng
force-pushed
the
finder-drag-behavior
branch
2 times, most recently
from
August 24, 2026 13:05
d32aacd to
ec81de3
Compare
goneng
marked this pull request as ready for review
August 24, 2026 13:13
Collaborator
Author
|
(rebased on-top of |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents accidental data loss when dragging changed/untracked files from GitX to Finder by limiting the allowed drag operation outside the app to Copy, so Finder won’t interpret the drag as a move that removes the file from the working copy.
Changes:
- Restrict
sourceOperationMaskForDraggingContext:toNSDragOperationCopywhen the drag leaves the application. - Keep the in-app drag operation mask unchanged (
NSDragOperationEvery) to preserve existing internal drag behaviors.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+28
to
35
| // Copying only once the drag leaves GitX: the files being dragged are the | ||
| // working copy, and a move takes them out of the repository. | ||
| - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context | ||
| { | ||
| if (context == NSDraggingContextOutsideApplication) | ||
| return NSDragOperationCopy; | ||
|
|
||
| return NSDragOperationEvery; |
Collaborator
Author
There was a problem hiding this comment.
Two assertions added: outside-application returns NSDragOperationCopy, within-application still returns NSDragOperationEvery
goneng
marked this pull request as draft
August 24, 2026 13:40
goneng
force-pushed
the
finder-drag-behavior
branch
from
August 24, 2026 14:28
deebbd9 to
ef9f2d2
Compare
goneng
marked this pull request as ready for review
August 24, 2026 14:33
goneng
force-pushed
the
finder-drag-behavior
branch
from
August 24, 2026 14:45
ef9f2d2 to
0fd1c1a
Compare
Offer a copy, rather than any operation the destination likes, once the drag has left GitX. - Restrict the source operation mask outside the application to a copy - Assert that a drag leaving GitX offers a copy and nothing else - Assert that a drag staying inside GitX still offers every operation, since staging and unstaging by drag depend on the move The mask has allowed every operation since the external drag was added in 2008, to let a changed file be opened in another editor. The Finder reads that as leave to move, so dragging a file to a Finder window takes it out of the working copy, and the index then reports it deleted. The tree view already restricts itself the same way.
goneng
force-pushed
the
finder-drag-behavior
branch
from
September 7, 2026 20:21
0fd1c1a to
4ee661d
Compare
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.
Offer a copy, rather than any operation the destination likes, once
the drag has left GitX.
This can lose files today
Dragging a changed file from the staged or unstaged list onto a Finder
window does not copy it. The Finder moves it, so the file leaves the
working copy and the list then reports it deleted.
Nothing warns, and nothing about the gesture suggests the file is being taken away, which
makes it easy to do by accident while meaning only to open or share a copy of it.
For a tracked file the damage is recoverable with
git checkout.For an untracked one it is not: the file is gone from the repository with
nothing in git recording that it was ever there.
Both lists show untracked files.
Where it comes from
The mask has allowed every operation since e76d483 (2008), the commit
that added the external drag in the first place, for a purpose that a
copy serves fully:
The comment that commit left in the data source still reads
// External, to drag them to for example XCode or Textmate.Opening a file elsewhere was the intent; relocating it was not.
A later commit carried the mask over to the current API without revisiting the value.
PBQLOutlineViewalready restricts itself to a copy, commented/* Needed to drag outside application */.This brings the two views into agreement.
Going to a file on disk is unaffected:
Reveal in Finder is in the context menu of both lists and in the main menu.
Test plan:
xcodebuild test -only-testing:GitXTestsis green, 42/42,and the build carries the same warnings as master
a file dragged from either list to a Finder window is copied and stays
in the working copy; a file dragged into a text editor still opens;
dragging between the two lists still stages and unstages