fix: restrict e to HEAD, add O to open historical files read-only (#2147)#2924
Open
Metbcy wants to merge 1 commit into
Open
fix: restrict e to HEAD, add O to open historical files read-only (#2147)#2924Metbcy wants to merge 1 commit into
e to HEAD, add O to open historical files read-only (#2147)#2924Metbcy wants to merge 1 commit into
Conversation
…gitui-org#2147) Editing a file via `e` on the Files-at-revision view used to open the current worktree copy regardless of which commit was being browsed, which was confusing and could lead to accidental edits attributed to the wrong revision. - `e` (edit) is now only enabled when viewing HEAD. - `O` (shift+o) is enabled only when viewing a non-HEAD commit; it dumps the blob to a read-only tempfile under a SHA-prefixed tempdir and opens it in $EDITOR. The tempdir is owned by the component and cleaned up on the next open or on Drop. - Switches to the Status tab on open so it is clear that edits will not be persisted to the historical revision. Closes gitui-org#2147
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.
This Pull Request fixes/closes #2147.
It changes the following:
e(edit) on the Files-at-revision view is now only enabled when the revision being viewed is HEAD. Previouslyealways opened the current worktree copy regardless of which commit you were browsing, which was confusing and could lead to edits being misattributed to the wrong revision.O(shift+o) command is enabled only on non-HEAD revisions. It writes the blob at the selected revision into a fresh tempdir (prefixed with the full commit SHA), marks the file read-only, and opens it in the external editor.RevisionFilesComponentand is cleaned up when the nextOreplaces it or when the component is dropped, so there is no on-disk leak.O, the view switches to the Status tab so it is visually clear that edits to the tempfile will not be persisted to the historical revision.Testing
A new unit test (
dumps_blob_to_readonly_tempfile_and_cleans_up_on_drop) covers the dump-to-readonly + drop-on-replace behavior. Full suite passes:I also smoke-tested manually on a small repo:
eon a fileOon a fileeO/tmp/<sha><rand>/<file>, correct blobNotes
is_head()returnsfalseon lookup error, which keeps the safe behavior of preferringopenoveredit.I followed the checklist:
make checkwithout errors (skippeddeny/tombilocally CI will likely cover)