summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/actions/init.lua40
-rw-r--r--lua/telescope/builtin/git.lua5
2 files changed, 43 insertions, 2 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index de6c58b..bee1f48 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -297,6 +297,38 @@ actions.insert_value = function(prompt_bufnr)
return entry.value
end
+--- Create and checkout a new git branch if it doesn't already exist
+---@param prompt_bufnr number: The prompt bufnr
+actions.git_create_branch = function(prompt_bufnr)
+ local cwd = action_state.get_current_picker(prompt_bufnr).cwd
+ local new_branch = action_state.get_current_line()
+
+ if new_branch == "" then
+ print('Please enter the name of the new branch to create')
+ else
+ local confirmation = vim.fn.input(string.format('Create new branch "%s"? [y/n]: ', new_branch))
+ if string.len(confirmation) == 0 or string.sub(string.lower(confirmation), 0, 1) ~= 'y' then
+ print(string.format('Didn\'t create branch "%s"', new_branch))
+ return
+ end
+
+ actions.close(prompt_bufnr)
+
+ local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '-b', new_branch }, cwd)
+ if ret == 0 then
+ print(string.format('Switched to a new branch: %s', new_branch))
+ else
+ print(string.format(
+ 'Error when creating new branch: %s Git returned "%s"',
+ new_branch,
+ table.concat(stderr, ' ')
+ ))
+ end
+ end
+end
+
+--- Checkout an existing git branch
+---@param prompt_bufnr number: The prompt bufnr
actions.git_checkout = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
@@ -313,6 +345,8 @@ actions.git_checkout = function(prompt_bufnr)
end
end
+--- Tell git to track the currently selected remote branch in Telescope
+---@param prompt_bufnr number: The prompt bufnr
actions.git_track_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
@@ -329,6 +363,8 @@ actions.git_track_branch = function(prompt_bufnr)
end
end
+--- Delete the currently selected branch
+---@param prompt_bufnr number: The prompt bufnr
actions.git_delete_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
@@ -349,6 +385,8 @@ actions.git_delete_branch = function(prompt_bufnr)
end
end
+--- Rebase to selected git branch
+---@param prompt_bufnr number: The prompt bufnr
actions.git_rebase_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
@@ -369,6 +407,8 @@ actions.git_rebase_branch = function(prompt_bufnr)
end
end
+--- Stage/unstage selected file
+---@param prompt_bufnr number: The prompt bufnr
actions.git_staging_toggle = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua
index b2270ad..f7c0096 100644
--- a/lua/telescope/builtin/git.lua
+++ b/lua/telescope/builtin/git.lua
@@ -177,11 +177,12 @@ git.branches = function(opts)
map('i', '<c-r>', actions.git_rebase_branch)
map('n', '<c-r>', actions.git_rebase_branch)
+ map('i', '<c-a>', actions.git_create_branch)
+ map('n', '<c-a>', actions.git_create_branch)
+
map('i', '<c-d>', actions.git_delete_branch)
map('n', '<c-d>', actions.git_delete_branch)
- map('i', '<c-u>', false)
- map('n', '<c-u>', false)
return true
end
}):find()