Skip to content

Commit

Permalink
fix(windows): treat both backslash and frontslash as path separators (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Apr 24, 2024
1 parent 96f0983 commit 3b3a6b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lua/oil/mutator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local cache = require("oil.cache")
local columns = require("oil.columns")
local config = require("oil.config")
local constants = require("oil.constants")
local fs = require("oil.fs")
local lsp_helpers = require("oil.lsp.helpers")
local oil = require("oil")
local parser = require("oil.mutator.parser")
Expand Down Expand Up @@ -99,7 +100,8 @@ M.create_actions_from_diffs = function(all_diffs)
table.insert(by_id, diff)
else
-- Parse nested files like foo/bar/baz
local pieces = vim.split(diff.name, "/")
local path_sep = fs.is_windows and "[/\\]" or "/"
local pieces = vim.split(diff.name, path_sep)
local url = parent_url:gsub("/$", "")
for i, v in ipairs(pieces) do
local is_last = i == #pieces
Expand Down
23 changes: 13 additions & 10 deletions lua/oil/mutator/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,26 @@ M.parse = function(bufnr)
end
local parsed_entry = result.data
local entry = result.entry
if not parsed_entry.name or parsed_entry.name:match("/") or not entry then
local message
if not parsed_entry.name then
message = "No filename found"
elseif not entry then
message = "Could not find existing entry (was the ID changed?)"
else
message = "Filename cannot contain '/'"
end

local err_message
if not parsed_entry.name then
err_message = "No filename found"
elseif not entry then
err_message = "Could not find existing entry (was the ID changed?)"
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
err_message = "Filename cannot contain path separator"
end
if err_message then
table.insert(errors, {
message = message,
message = err_message,
lnum = i - 1,
end_lnum = i,
col = 0,
})
goto continue
end
assert(entry)

check_dupe(parsed_entry.name, i)
local meta = entry[FIELD_META]
if original_entries[parsed_entry.name] == parsed_entry.id then
Expand Down

0 comments on commit 3b3a6b2

Please sign in to comment.