Skip to content

Commit

Permalink
get branches
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed Aug 13, 2024
1 parent dd5282d commit b3a3328
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions .config/nvim/lua/plugins/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ local actions_pretty_print = function(message)
require('user.utils').pretty_print(message, 'Git Actions', '')
end

local function get_branches(remote_name)
local cmd_output = vim.system({ 'git', 'ls-remote', '--heads', remote_name }):wait()
-- split cmd_output.stdout by new line
cmd_output = vim.split(cmd_output.stdout, '\n')
local branches = {}
for _, line in ipairs(cmd_output) do
table.insert(branches, string.match(line, 'heads/(.*)$'))
end
return branches
end

local function create_new_branch(branch_opts)
if branch_opts.args ~= '' then
return vim.cmd('Git checkout -b ' .. branch_opts.args)
Expand Down Expand Up @@ -83,7 +94,7 @@ local actions = function()
end,
['Pull {remote} {branch}'] = function()
get_remotes(function(remote)
vim.ui.input({ default = 'main', prompt = 'Enter branch to pull from: ' }, function(branch_to_pull)
vim.ui.select(get_branches(remote), { prompt = 'Select branch to pull from: ' }, function(branch_to_pull)
if not branch_to_pull then
actions_pretty_print 'Canceled.'
return
Expand All @@ -95,7 +106,7 @@ local actions = function()
end,
['Merge {remote} {branch}'] = function()
get_remotes(function(remote)
vim.ui.input({ default = 'main', prompt = 'Enter branch to merge with: ' }, function(branch_to_merge)
vim.ui.select(get_branches(remote), { prompt = 'Select branch to merge with: ' }, function(branch_to_merge)
if not branch_to_merge then
actions_pretty_print 'Canceled.'
return
Expand Down

0 comments on commit b3a3328

Please sign in to comment.