Fix: use_git_branch in a non git repo caused error
Using `use_git_branch` in a non git enabled repo caused an error. This has been addressed by checking for the presence of a `.git` folder in the cwd. If no branch has been specified then we default to HEAD via the addition of `2>/dev/null` in our shell commandmain
parent
2d6a222073
commit
76a994c185
|
|
@ -10,10 +10,13 @@ function M.get_current()
|
|||
end
|
||||
|
||||
function M.get_branch()
|
||||
if Config.options.use_git_branch == true then
|
||||
local branch = vim.api.nvim_exec([[!git rev-parse --abbrev-ref HEAD]], true)
|
||||
-- The command returns two lines. We only need the second one
|
||||
lines = {}
|
||||
local git_enabled = (vim.fn.isdirectory(vim.fn.getcwd()..'/.git') == 1)
|
||||
|
||||
if Config.options.use_git_branch == true and git_enabled == true then
|
||||
local branch = vim.api.nvim_exec([[!git rev-parse --abbrev-ref HEAD 2>/dev/null]], true)
|
||||
|
||||
-- The branch command returns two lines. We only need the second line
|
||||
local lines = {}
|
||||
for s in branch:gmatch("[^\r\n]+") do
|
||||
table.insert(lines, '_' .. s)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue