Skip to content

fix: crash on case-only filename renames (case-insensitive filesystems) - #779 - #791

Open
theAnuragMishra wants to merge 1 commit into
stevearc:masterfrom
theAnuragMishra:fix/case-only-renames
Open

theAnuragMishra wants to merge 1 commit into
stevearc:masterfrom
theAnuragMishra:fix/case-only-renames

Conversation

@theAnuragMishra

Copy link
Copy Markdown

Renaming a file via oil where only the case changes (test.java ->
Test.java) throws invalid buffer error on a case-insensitive filesystem, but only if the file was already
open in a buffer.

Cause:
vim.fn.bufadd(dest_buf_name) resolves to the same buffer as
src_bufnr when the two names differ only in case, since they point
to the same inode. rename_buffer's swap logic assumes src_bufnr
and dest_bufnr are always distinct, so it deletes src_bufnr and
then accesses dest_bufnr (the now-deleted same buffer) right after.

Fix:
Short-circuit when dest_bufnr == src_bufnr: just rename the buffer
in place and clean up the old-name buffer.

fixes #778

On case-insensitive filesystems, renaming a file with only a case
change (e.g. test.java -> Test.java) causes bufadd(dest_buf_name) to
resolve to the same buffer as src_bufnr instead of creating a new one.
The existing src/dest buffer-swap logic assumes two distinct buffers,
so it deletes the only buffer that exists and then tries to use it
again, throwing "invalid buffer id".

Add a short-circuit for dest_bufnr == src_bufnr that just updates the
buffer's display name.
@github-actions
github-actions Bot requested a review from stevearc October 14, 2026 23:16
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.

bug: invalid buffer error on renaming

1 participant