From 13dd021d6afbfc4cab626c16ef4486c41c55adfa Mon Sep 17 00:00:00 2001 From: Chris Antos Date: Sun, 7 Dec 2025 19:52:40 -0800 Subject: [PATCH] Fix branch name in a newly inited repo. "git branch" does not work in a newly inited repo. So in a newly inited using reftables, the branch name was not able to be retrieved, and the "Loading..." placeholder remained indefinitely. This change updates it to try again with "git branch --show-current" when "git branch" prints empty output. --- vendor/clink.lua | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index ae5d545..70c6693 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -348,17 +348,36 @@ local function get_git_branch(git_dir, fast) -- If the branch name is ".invalid" and the fast method wasn't requested, -- then invoke git.exe to get accurate current branch info (slow method). if branch_name == ".invalid" and not fast then - local file = io_popenyield("git --no-optional-locks branch 2>nul") - if file then - for line in file:lines() do -- luacheck: ignore 512 - local b = line:match("^%*%s+(.*)") - if b then - b = b:match("^%((HEAD detached at .*)%)") or b - branch_name = b + local file + branch_name = nil + + -- Handle the most common case first. + if not branch_name then + file = io_popenyield("git --no-optional-locks branch 2>nul") + if file then + for line in file:lines() do + local b = line:match("^%*%s+(.*)") + if b then + b = b:match("^%((HEAD detached at .*)%)") or b + branch_name = b + break + end + end + file:close() + end + end + + -- Handle the cases where "git branch" output is empty, but "git + -- branch --show-current" shows the branch name (e.g. a new repo). + if not branch_name then + file = io_popenyield("git --no-optional-locks branch --show-current 2>nul") + if file then + for line in file:lines() do -- luacheck: ignore 512 + branch_name = line break end + file:close() end - file:close() end else branch_name = branch_name or 'HEAD detached at '..HEAD:sub(1, 7)