From c473ee1e3ae969d37d4cddc7d2381d5cc2aa3628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 20 Aug 2023 11:27:02 +0200 Subject: [PATCH] fix: Check local reference of remote branch first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lua/openingh/utils.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/openingh/utils.lua b/lua/openingh/utils.lua index 6e965dc..30a58e9 100644 --- a/lua/openingh/utils.lua +++ b/lua/openingh/utils.lua @@ -60,7 +60,13 @@ end -- Checks if the supplied branch is available on the remote 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 ~= "" end