Skip to content

Commit

Permalink
When upstream doesn't exist in repo state, attempt to get it via CLI
Browse files Browse the repository at this point in the history
call
  • Loading branch information
CKolkey committed Aug 3, 2023
1 parent f3971c6 commit 02f45be
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lua/neogit/lib/git/branch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 02f45be

Please sign in to comment.