Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lua/neogit/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,15 @@ function M.try(fn, ...)
end
end

---@param str string
---@param prefix string
---@return string
function M.remove_prefix(str, prefix)
if str:sub(1, #prefix) == prefix then
return str:sub(#prefix + 1)
else
return str
end
end

return M
8 changes: 5 additions & 3 deletions lua/neogit/popups/push/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,19 @@ function M.push_other(popup)
end

local destinations = git.refs.list_remote_branches()
for _, remote in ipairs(git.remote.list()) do
table.insert(destinations, 1, remote .. "/" .. source)
end

local destination = FuzzyFinderBuffer.new(util.deduplicate(destinations))
:open_async { prompt_prefix = "push " .. source .. " to" }

if not destination then
return
end

local remote, _ = git.branch.parse_remote_branch(destination)

-- destination is <remote>/branch-name, need to remove the remote prefix
destination = util.remove_prefix(destination, remote .. "/")

push_to(popup:get_arguments(), remote, source .. ":" .. destination)
end

Expand Down
Loading