Skip to content

Commit

Permalink
feat: wrap remaining destructive Git actions in a confirm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tssm authored and ibhagwan committed Aug 18, 2024
1 parent 69e49be commit 0d1b399
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,21 +719,25 @@ M.git_stage_unstage = function(selected, opts)
end

M.git_reset = function(selected, opts)
for _, s in ipairs(selected) do
s = utils.strip_ansi_coloring(s)
local is_untracked = s:sub(5, 5) == "?"
local cmd = is_untracked
and path.git_cwd({ "git", "clean", "-f" }, opts)
or path.git_cwd({ "git", "checkout", "HEAD", "--" }, opts)
git_exec({ s }, opts, cmd)
-- trigger autoread or warn the users buffer(s) was changed
vim.cmd("checktime")
if vim.fn.confim("Reset " .. #selected .. " file(s)?", "&Yes\n&No") == 1 then
for _, s in ipairs(selected) do
s = utils.strip_ansi_coloring(s)
local is_untracked = s:sub(5, 5) == "?"
local cmd = is_untracked
and path.git_cwd({ "git", "clean", "-f" }, opts)
or path.git_cwd({ "git", "checkout", "HEAD", "--" }, opts)
git_exec({ s }, opts, cmd)
-- trigger autoread or warn the users buffer(s) was changed
vim.cmd("checktime")
end
end
end

M.git_stash_drop = function(selected, opts)
local cmd = path.git_cwd({ "git", "stash", "drop" }, opts)
git_exec(selected, opts, cmd)
if vim.fn.confirm("Drop " .. #selected .. " stash(es)?", "&Yes\n&No") == 1 then
local cmd = path.git_cwd({ "git", "stash", "drop" }, opts)
git_exec(selected, opts, cmd)
end
end

M.git_stash_pop = function(selected, opts)
Expand Down

0 comments on commit 0d1b399

Please sign in to comment.