From d434627738c59473530d807cb645df6deb4c8e80 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 7 Aug 2021 02:32:12 +0800 Subject: [PATCH] Fix: the loading condition for fugitive is wrong We should load fugitive in the following two situations: + When we open nvim in a Git repository + When we are inside nvim and change the working directory to a Git reposity --- autoload/utils.vim | 14 ++++++++++++++ core/autocommands.vim | 5 +++++ lua/plugins.lua | 10 +--------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/autoload/utils.vim b/autoload/utils.vim index 9d84c9b..8ed401e 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -145,3 +145,17 @@ function! utils#Get_titlestr() abort return l:title_str endfunction + +" Check if we are inside a Git repo. +function! utils#Inside_git_repo() abort + let res = system('git rev-parse --is-inside-work-tree') + if match(res, 'true') == -1 + return v:false + else + " Manually trigger a speical user autocmd InGitRepo (to use it for + " lazyloading of fugitive by packer.nvim). + " See also https://github.com/wbthomason/packer.nvim/discussions/534. + doautocmd User InGitRepo + return v:true + endif +endfunction diff --git a/core/autocommands.vim b/core/autocommands.vim index 1cc207a..2563ce7 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -89,4 +89,9 @@ function! s:quit_current_win() abort quit endif endfunction + +augroup git_repo_check + autocmd! + autocmd VimEnter,DirChanged * call utils#Inside_git_repo() +augroup END "} diff --git a/lua/plugins.lua b/lua/plugins.lua index ccc01af..7daf987 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -178,15 +178,7 @@ require('packer').startup( -- use 'airblade/vim-gitgutter' -- Git command inside vim - use {'tpope/vim-fugitive', cond = - function() - local res = vim.fn.system('git rev-parse --is-inside-work-tree') - if string.find(res, 'true') then - return true - else - return false - end - end} + use {'tpope/vim-fugitive', event = 'User InGitRepo'} -- Better git log display use {'rbong/vim-flog', require = 'tpope/vim-fugitive', cmd = {'Flog'}}