Skip to content

fix: restrict e to HEAD, add O to open historical files read-only (#2147)#2924

Open
Metbcy wants to merge 1 commit into
gitui-org:masterfrom
Metbcy:fix-2147-edit-only-head
Open

fix: restrict e to HEAD, add O to open historical files read-only (#2147)#2924
Metbcy wants to merge 1 commit into
gitui-org:masterfrom
Metbcy:fix-2147-edit-only-head

Conversation

@Metbcy
Copy link
Copy Markdown

@Metbcy Metbcy commented May 16, 2026

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. Previously e always 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.
  • A new 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.
  • The tempdir is owned by the RevisionFilesComponent and is cleaned up when the next O replaces it or when the component is dropped, so there is no on-disk leak.
  • On 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:

cargo nextest run --workspace
# 310 tests, 0 failed

I also smoke-tested manually on a small repo:

Scenario Expected Actual
At HEAD, e on a file Opens worktree copy (writable) ✅ perms 644, real path
At HEAD, O on a file Ignored ✅ no-op
At older commit, e Ignored ✅ no-op
At older commit, O Opens tempfile, read-only, historical content ✅ perms 444, /tmp/<sha><rand>/<file>, correct blob
Open a second file at the same revision Previous tempdir dropped first ✅ old tempdir gone
Quit gitui Tempdir removed

Notes

  • Previous attempt at this issue (Issue 2147 #2384) was closed by its author with the checklist unfinished; this PR is an independent implementation.
  • is_head() returns false on lookup error, which keeps the safe behavior of preferring open over edit.

I followed the checklist:

  • I added unittests
  • I ran make check without errors (skipped deny/tombi locally CI will likely cover)
  • I tested the overall application
  • I added an appropriate item to the changelog

…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
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.

edit only for head revision otherwise open as tempfile

1 participant