From 2d39a243e7bf58dfa212a19d1c5a0e2966b421bc Mon Sep 17 00:00:00 2001 From: Shadman Date: Fri, 8 Jan 2021 15:51:11 +0600 Subject: [PATCH] Fix branch not changing (#48) * Fix branch not changing * Added stderr detection to remove git_branch * fixed bug in terminal windows * changed error handling to pcall instead of match Co-authored-by: hoob3rt --- lua/lualine/components/branch.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lua/lualine/components/branch.lua b/lua/lualine/components/branch.lua index a63cbe2..a687137 100644 --- a/lua/lualine/components/branch.lua +++ b/lua/lualine/components/branch.lua @@ -8,12 +8,25 @@ local get_git_branch = async:new({ if data then git_branch = data:gsub('\n', '') end - end + end, + on_stderr = function (_, data) + if data then + if data:find("fatal: not a git repository") then + git_branch = '' + end + end + end, }) local timer = vim.loop.new_timer() timer:start(0, 1000, vim.schedule_wrap(function() - get_git_branch:start() + local cur_dir = vim.fn.getcwd() + local buffer_working_directory = vim.fn.expand("%:p:h") + local status, _ = pcall(vim.api.nvim_set_current_dir, buffer_working_directory) + if status == true then + get_git_branch:start() + vim.api.nvim_set_current_dir(cur_dir) + end end)) local function branch()