fix(git): handle untracked directories in action_discard

This commit is contained in:
2026-04-27 14:27:36 +02:00
parent f653d8eafe
commit 0e0edbc418
+13 -4
View File
@@ -805,11 +805,20 @@ local function action_discard()
local prompt, action
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()
local ok, err = os.remove(vim.fs.joinpath(s.worktree, entry.path))
if not ok then
log.error("failed to remove %s: %s", entry.path, err or "")
local target = vim.fs.joinpath(s.worktree, entry.path)
local rc = vim.fn.delete(target, is_dir and "rf" or "")
if rc ~= 0 then
log.error("failed to delete %s", entry.path)
end
refresh(vim.api.nvim_get_current_buf())
end