From 15b0d414c136e3475629ea1c7d8fa98b615915b5 Mon Sep 17 00:00:00 2001 From: linrongbin16 Date: Tue, 28 Nov 2023 18:11:02 +0800 Subject: [PATCH] fix(default_branch): use real-time remote (#163) --- lua/gitlinker/git.lua | 6 ++++-- lua/gitlinker/linker.lua | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/gitlinker/git.lua b/lua/gitlinker/git.lua index 93b2264..e3f9cae 100644 --- a/lua/gitlinker/git.lua +++ b/lua/gitlinker/git.lua @@ -393,9 +393,11 @@ local function get_branch_remote() return nil end +--- @param remote string --- @return string? -local function get_default_branch() - local args = { "git", "rev-parse", "--abbrev-ref", "origin/HEAD" } +local function get_default_branch(remote) + local args = + { "git", "rev-parse", "--abbrev-ref", string.format("%s/HEAD", remote) } local result = cmd(args) if type(result.stdout) ~= "table" or #result.stdout == 0 then return nil diff --git a/lua/gitlinker/linker.lua b/lua/gitlinker/linker.lua index 4c8e558..a558a6c 100644 --- a/lua/gitlinker/linker.lua +++ b/lua/gitlinker/linker.lua @@ -177,7 +177,7 @@ local function make_linker() -- vim.inspect(buf_path_on_cwd) -- ) - local default_branch = git.get_default_branch() + local default_branch = git.get_default_branch(remote) local current_branch = git.get_current_branch() local o = {