diff --git a/nvim/files/lua/plugins/snacks.lua b/nvim/files/lua/plugins/snacks.lua index 5a7ba60..4e93103 100644 --- a/nvim/files/lua/plugins/snacks.lua +++ b/nvim/files/lua/plugins/snacks.lua @@ -239,10 +239,16 @@ return { end -- Get the default branch + local function branch_exists(branch) + local result = git_cmd("git rev-parse --verify refs/remotes/origin/" .. branch) + -- If branch exists, rev-parse returns a hash; if not, it returns fatal error + return not result:match("^fatal") + end + local default_branch = nil - if git_cmd("git show-ref --verify --quiet refs/remotes/origin/main") == "" then + if branch_exists("main") then default_branch = "main" - elseif git_cmd("git show-ref --verify --quiet refs/remotes/origin/master") == "" then + elseif branch_exists("master") then default_branch = "master" end