From 0e0edbc4188d2c1dd09f182d6a5b3e541da214b3 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 27 Apr 2026 14:27:36 +0200 Subject: [PATCH] fix(git): handle untracked directories in action_discard --- lua/git/status_win.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lua/git/status_win.lua b/lua/git/status_win.lua index feb00da..e45a142 100644 --- a/lua/git/status_win.lua +++ b/lua/git/status_win.lua @@ -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