From 9e26823ea6c7361aba3253c8a5c56a6f35b4a0ee Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 25 Dec 2021 16:13:39 +0600 Subject: [PATCH] fixup: error on branch component when stray .git files exist fixes #490 --- doc/lualine.txt | 2 +- lua/lualine/components/branch/git_branch.lua | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/lualine.txt b/doc/lualine.txt index ee6d5a4..2fcb854 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -347,7 +347,7 @@ in component. theme = 'auto', -- lualine theme component_separators = {left = '', right = ''}, section_separators = {left = '', right = ''}, - disabled_filetypes = {}, -- filetypes to diable lualine on + disabled_filetypes = {}, -- filetypes to disable lualine on always_divide_middle = true, -- When true left_sections (a,b,c) can't -- take over entiee statusline even -- when none of section x, y, z is present. diff --git a/lua/lualine/components/branch/git_branch.lua b/lua/lualine/components/branch/git_branch.lua index 9505fdf..8841e8b 100644 --- a/lua/lualine/components/branch/git_branch.lua +++ b/lua/lualine/components/branch/git_branch.lua @@ -78,9 +78,11 @@ function M.find_git_dir(dir_path) elseif git_file_stat.type == 'file' then -- separate git-dir or submodule is used local file = io.open(git_path) - git_dir = file:read() - git_dir = git_dir:match 'gitdir: (.+)$' - file:close() + if file then + git_dir = file:read() + git_dir = git_dir and git_dir:match 'gitdir: (.+)$' + file:close() + end -- submodule / relative file path if git_dir and git_dir:sub(1, 1) ~= sep and not git_dir:match '^%a:.*$' then git_dir = git_path:match '(.*).git' .. git_dir