feat: extend git_delete_branch to delete of all selected branches (#2337)
This commit is contained in:
@@ -2719,7 +2719,7 @@ actions.git_track_branch({prompt_bufnr}) *telescope.actions.git_track_branch()*
|
|||||||
|
|
||||||
|
|
||||||
actions.git_delete_branch({prompt_bufnr}) *telescope.actions.git_delete_branch()*
|
actions.git_delete_branch({prompt_bufnr}) *telescope.actions.git_delete_branch()*
|
||||||
Delete the currently selected branch
|
Delete all currently selected branches
|
||||||
|
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
|
|||||||
@@ -685,18 +685,34 @@ actions.git_track_branch = make_git_branch_action {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Delete the currently selected branch
|
--- Delete all currently selected branches
|
||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
actions.git_delete_branch = make_git_branch_action {
|
actions.git_delete_branch = function(prompt_bufnr)
|
||||||
should_confirm = true,
|
local confirmation = vim.fn.input "Do you really want to delete the selected branches? [Y/n] "
|
||||||
action_name = "actions.git_delete_branch",
|
if confirmation ~= "" and string.lower(confirmation) ~= "y" then
|
||||||
confirmation_question = "Do you really wanna delete branch %s? [Y/n] ",
|
return
|
||||||
success_message = "Deleted branch: %s",
|
end
|
||||||
error_message = "Error when deleting branch: %s. Git returned: '%s'",
|
|
||||||
command = function(branch_name)
|
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||||
return { "git", "branch", "-D", branch_name }
|
local action_name = "actions.git_delete_branch"
|
||||||
end,
|
picker:delete_selection(function(selection)
|
||||||
}
|
local branch = selection.value
|
||||||
|
print("Deleting branch " .. branch)
|
||||||
|
local _, ret, stderr = utils.get_os_command_output({ "git", "branch", "-D", branch }, picker.cwd)
|
||||||
|
if ret == 0 then
|
||||||
|
utils.notify(action_name, {
|
||||||
|
msg = string.format("Deleted branch: %s", branch),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
|
else
|
||||||
|
utils.notify(action_name, {
|
||||||
|
msg = string.format("Error when deleting branch: %s. Git returned: '%s'", branch, table.concat(stderr, " ")),
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return ret == 0
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
--- Merge the currently selected branch
|
--- Merge the currently selected branch
|
||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
|
|||||||
Reference in New Issue
Block a user