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
|
end
|
||||||
|
|
||||||
function M.get_branch()
|
function M.get_branch()
|
||||||
if Config.options.use_git_branch == true then
|
local git_enabled = (vim.fn.isdirectory(vim.fn.getcwd()..'/.git') == 1)
|
||||||
local branch = vim.api.nvim_exec([[!git rev-parse --abbrev-ref HEAD]], true)
|
|
||||||
-- The command returns two lines. We only need the second one
|
if Config.options.use_git_branch == true and git_enabled == true then
|
||||||
lines = {}
|
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
|
for s in branch:gmatch("[^\r\n]+") do
|
||||||
table.insert(lines, '_' .. s)
|
table.insert(lines, '_' .. s)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue