From 2e6cbe522c788a0bb0c5ade55f05480ca8be8293 Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Wed, 13 Aug 2025 17:30:22 +0100 Subject: [PATCH 1/2] fix push other workflow --- lua/neogit/popups/push/actions.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lua/neogit/popups/push/actions.lua b/lua/neogit/popups/push/actions.lua index 26fd6df56..bc49257d1 100644 --- a/lua/neogit/popups/push/actions.lua +++ b/lua/neogit/popups/push/actions.lua @@ -111,6 +111,14 @@ function M.to_elsewhere(popup) end end +local function remove_prefix(str, prefix) + if str:sub(1, #prefix) == prefix then + return str:sub(#prefix + 1) + else + return str + end +end + function M.push_other(popup) local sources = util.merge({ popup.state.env.commit }, git.refs.list_local_branches(), git.refs.heads()) local source = FuzzyFinderBuffer.new(sources):open_async { prompt_prefix = "push" } @@ -119,17 +127,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 = remove_prefix(destination, remote .. "/") + push_to(popup:get_arguments(), remote, source .. ":" .. destination) end From 19c01cfb6b712b8c4b7c3d0c038010981c319af8 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 25 Aug 2025 21:18:14 +0200 Subject: [PATCH 2/2] Move "remove_prefix" util function to util lib --- lua/neogit/lib/util.lua | 11 +++++++++++ lua/neogit/popups/push/actions.lua | 12 ++---------- 2 files changed, 13 insertions(+), 10 deletions(-) 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 bc49257d1..4c50aa343 100644 --- a/lua/neogit/popups/push/actions.lua +++ b/lua/neogit/popups/push/actions.lua @@ -111,14 +111,6 @@ function M.to_elsewhere(popup) end end -local function remove_prefix(str, prefix) - if str:sub(1, #prefix) == prefix then - return str:sub(#prefix + 1) - else - return str - end -end - function M.push_other(popup) local sources = util.merge({ popup.state.env.commit }, git.refs.list_local_branches(), git.refs.heads()) local source = FuzzyFinderBuffer.new(sources):open_async { prompt_prefix = "push" } @@ -136,9 +128,9 @@ function M.push_other(popup) end local remote, _ = git.branch.parse_remote_branch(destination) - -- + -- destination is /branch-name, need to remove the remote prefix - destination = remove_prefix(destination, remote .. "/") + destination = util.remove_prefix(destination, remote .. "/") push_to(popup:get_arguments(), remote, source .. ":" .. destination) end