From 76a994c18535fc000b1384e0861a28660ec29e60 Mon Sep 17 00:00:00 2001 From: olimorris Date: Wed, 8 Sep 2021 17:01:06 +0100 Subject: [PATCH] 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 command --- lua/persistence/init.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/persistence/init.lua b/lua/persistence/init.lua index f99815b..b71e4e7 100644 --- a/lua/persistence/init.lua +++ b/lua/persistence/init.lua @@ -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