From 02f45be29c856f14230f8d0ea3a240e2a071a001 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 3 Aug 2023 14:10:50 +0200 Subject: [PATCH] When upstream doesn't exist in repo state, attempt to get it via CLI call --- lua/neogit/lib/git/branch.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lua/neogit/lib/git/branch.lua b/lua/neogit/lib/git/branch.lua index b9fdd0674..be522f1b6 100644 --- a/lua/neogit/lib/git/branch.lua +++ b/lua/neogit/lib/git/branch.lua @@ -124,7 +124,28 @@ function M.set_pushRemote() end function M.upstream() - return require("neogit.lib.git").repo.upstream.ref + local upstream = require("neogit.lib.git").repo.upstream.ref + + if upstream then + return upstream + else + local full_name = cli["rev-parse"] + .abbrev_ref() + .show_popup(false) + .args("@{upstream}") + .call_sync_ignoring_exit_code() + :trim().stdout + + local current = M.current() + + if #full_name > 0 and current then + local remote = config_lib.get("branch." .. current .. ".remote") + + if remote:is_set() then + return string.format("%s/%s", remote.value, full_name[1]:sub(#remote.value + 2, -1)) + end + end + end end function M.upstream_label()