diff --git a/lua/neogit/lib/util.lua b/lua/neogit/lib/util.lua index 46c9942f6..2a763e23d 100644 --- a/lua/neogit/lib/util.lua +++ b/lua/neogit/lib/util.lua @@ -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 diff --git a/lua/neogit/popups/push/actions.lua b/lua/neogit/popups/push/actions.lua index 26fd6df56..4c50aa343 100644 --- a/lua/neogit/popups/push/actions.lua +++ b/lua/neogit/popups/push/actions.lua @@ -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 /branch-name, need to remove the remote prefix + destination = util.remove_prefix(destination, remote .. "/") + push_to(popup:get_arguments(), remote, source .. ":" .. destination) end