fix: Check local reference of remote branch first

git ls-remote turns out to be slow, so checking for the local remote
branches first to determine if a branch exists upstream. This might not
work in all cases (e.g. if a branch was deleted remotely but no fetch
happened), but is probably good enough for most cases.

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2023-08-20 11:27:02 +02:00
parent 2719e5759e
commit c473ee1e3a
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF

View file

@ -60,7 +60,13 @@ end
-- Checks if the supplied branch is available on the remote -- Checks if the supplied branch is available on the remote
function M.is_branch_upstreamed(branch) function M.is_branch_upstreamed(branch)
local output = M.trim(vim.fn.system("git ls-remote --exit-code --heads origin " .. branch)) local output = M.trim(vim.fn.system("git branch -r --list origin/" .. branch))
if output:find(branch, 1, true) then
return true
end
-- ls-remote is more expensive so only use it as a fallback
output = M.trim(vim.fn.system("git ls-remote --exit-code --heads origin " .. branch))
return output ~= "" return output ~= ""
end end