fix(git): handle untracked directories in action_discard
This commit is contained in:
+13
-4
@@ -805,11 +805,20 @@ local function action_discard()
|
|||||||
|
|
||||||
local prompt, action
|
local prompt, action
|
||||||
if entry.section == "Untracked" then
|
if entry.section == "Untracked" then
|
||||||
prompt = string.format("Delete untracked file %s?", entry.path)
|
-- Porcelain v1 collapses untracked directories into a single
|
||||||
|
-- entry with a trailing slash, so plain `os.remove` (which only
|
||||||
|
-- deletes files / empty dirs) won't do.
|
||||||
|
local is_dir = entry.path:sub(-1) == "/"
|
||||||
|
prompt = string.format(
|
||||||
|
"Delete untracked %s %s?",
|
||||||
|
is_dir and "directory" or "file",
|
||||||
|
entry.path
|
||||||
|
)
|
||||||
action = function()
|
action = function()
|
||||||
local ok, err = os.remove(vim.fs.joinpath(s.worktree, entry.path))
|
local target = vim.fs.joinpath(s.worktree, entry.path)
|
||||||
if not ok then
|
local rc = vim.fn.delete(target, is_dir and "rf" or "")
|
||||||
log.error("failed to remove %s: %s", entry.path, err or "")
|
if rc ~= 0 then
|
||||||
|
log.error("failed to delete %s", entry.path)
|
||||||
end
|
end
|
||||||
refresh(vim.api.nvim_get_current_buf())
|
refresh(vim.api.nvim_get_current_buf())
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user