summaryrefslogtreecommitdiff
path: root/lua/telescope/actions/init.lua
diff options
context:
space:
mode:
authorJoel Palmer <joelpalmer@users.noreply.github.com>2021-07-29 16:16:45 -0500
committerGitHub <noreply@github.com>2021-07-30 00:16:45 +0300
commitb742c50bf119d7c442a553cc52e8afde0086ae02 (patch)
tree5d3fa49aa54a157394d2328b3ce8d48754cedb6a /lua/telescope/actions/init.lua
parent82f4d3028b64ad930123a5c713c538c872185a80 (diff)
feat: add git reset action for git commits picker (#999)
Diffstat (limited to 'lua/telescope/actions/init.lua')
-rw-r--r--lua/telescope/actions/init.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index c048d50..4ee6134 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -526,6 +526,42 @@ actions.git_rebase_branch = function(prompt_bufnr)
end
end
+local git_reset_branch = function(prompt_bufnr, mode)
+ local cwd = action_state.get_current_picker(prompt_bufnr).cwd
+ local selection = action_state.get_selected_entry()
+
+ local confirmation = vim.fn.input("Do you really wanna " .. mode .. " reset to " .. selection.value .. "? [Y/n] ")
+ if confirmation ~= "" and string.lower(confirmation) ~= "y" then
+ return
+ end
+
+ actions.close(prompt_bufnr)
+ local _, ret, stderr = utils.get_os_command_output({ "git", "reset", mode, selection.value }, cwd)
+ if ret == 0 then
+ print("Reset to: " .. selection.value)
+ else
+ print(string.format('Error when resetting to: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")))
+ end
+end
+
+--- Reset to selected git commit using mixed mode
+---@param prompt_bufnr number: The prompt bufnr
+actions.git_reset_mixed = function(prompt_bufnr)
+ git_reset_branch(prompt_bufnr, "--mixed")
+end
+
+--- Reset to selected git commit using soft mode
+---@param prompt_bufnr number: The prompt bufnr
+actions.git_reset_soft = function(prompt_bufnr)
+ git_reset_branch(prompt_bufnr, "--soft")
+end
+
+--- Reset to selected git commit using hard mode
+---@param prompt_bufnr number: The prompt bufnr
+actions.git_reset_hard = function(prompt_bufnr)
+ git_reset_branch(prompt_bufnr, "--hard")
+end
+
actions.git_checkout_current_buffer = function(prompt_bufnr)
local cwd = actions.get_current_picker(prompt_bufnr).cwd
local selection = actions.get_selected_entry()