Skip to content

Commit 6e2305f

Browse files
CKolkeyactionshrimp
authored andcommitted
Move "remove_prefix" util function to util lib
1 parent 201862f commit 6e2305f

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lua/neogit/lib/util.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,4 +623,15 @@ function M.try(fn, ...)
623623
end
624624
end
625625

626+
---@param str string
627+
---@param prefix string
628+
---@return string
629+
function M.remove_prefix(str, prefix)
630+
if str:sub(1, #prefix) == prefix then
631+
return str:sub(#prefix + 1)
632+
else
633+
return str
634+
end
635+
end
636+
626637
return M

lua/neogit/popups/push/actions.lua

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ function M.to_elsewhere(popup)
111111
end
112112
end
113113

114-
local function remove_prefix(str, prefix)
115-
if str:sub(1, #prefix) == prefix then
116-
return str:sub(#prefix + 1)
117-
else
118-
return str
119-
end
120-
end
121-
122114
function M.push_other(popup)
123115
local sources = util.merge({ popup.state.env.commit }, git.refs.list_local_branches(), git.refs.heads())
124116
local source = FuzzyFinderBuffer.new(sources):open_async { prompt_prefix = "push" }
@@ -136,9 +128,9 @@ function M.push_other(popup)
136128
end
137129

138130
local remote, _ = git.branch.parse_remote_branch(destination)
139-
--
131+
140132
-- destination is <remote>/branch-name, need to remove the remote prefix
141-
destination = remove_prefix(destination, remote .. "/")
133+
destination = util.remove_prefix(destination, remote .. "/")
142134

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

0 commit comments

Comments
 (0)