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 <pelczarskihubert@gmail.com>
This commit is contained in:
Shadman 2021-01-08 15:51:11 +06:00 committed by GitHub
parent 75a9c5c317
commit 2d39a243e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -8,12 +8,25 @@ local get_git_branch = async:new({
if data then
git_branch = data:gsub('\n', '')
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()
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()