Skip to content

fix(#2813): macos: enable file renaming with changed capitalization #2814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lua/nvim-tree/actions/fs/rename-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ local function err_fmt(from, to, reason)
return string.format("Cannot rename %s -> %s: %s", from, to, reason)
end

local function rename_file_exists(node, to)
if not utils.is_macos then
return utils.file_exists(to)
end

if string.lower(node) == string.lower(to) then
return false
end

return utils.file_exists(to)
end

---@param node Node
---@param to string
function M.rename(node, to)
local notify_from = notify.render_path(node.absolute_path)
local notify_to = notify.render_path(to)

if utils.file_exists(to) then
if rename_file_exists(notify_from, notify_to) then
notify.warn(err_fmt(notify_from, notify_to, "file already exists"))
return
end
Expand Down Expand Up @@ -65,7 +77,7 @@ function M.rename(node, to)
notify.warn(err_fmt(notify_from, notify_to, err))
return
end
elseif not utils.file_exists(path_to_create) then
elseif not rename_file_exists(notify_from, path_to_create) then
local success = vim.loop.fs_mkdir(path_to_create, 493)
if not success then
notify.error("Could not create folder " .. notify.render_path(path_to_create))
Expand Down
Loading