From 4c6aa4401b6e06d5f4863505c56af7eca3b7d41b Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Sun, 8 Sep 2013 14:03:49 +0000 Subject: [PATCH] check the git/hg root when changing buffers. resolves #237. --- autoload/airline/extensions/branch.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 0aa3da5..8a83a31 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -27,12 +27,24 @@ function! airline#extensions#branch#get_head() endif endif - return empty(head) + return empty(head) || !s:check_in_path() \ ? s:empty_message \ : printf('%s%s', empty(s:symbol) ? '' : s:symbol.' ', head) endfunction -function! airline#extensions#branch#init(ext) - call airline#parts#define_function('branch', 'airline#extensions#branch#get_head') +function! s:check_in_path() + if !exists('b:airline_branch_path') + let root = get(b:, 'git_dir', get(b:, 'mercurial_dir', '')) + let bufferpath = resolve(fnamemodify(expand('%'), ':p:h')) + let root = fnamemodify(root, ':h') + let b:airline_file_in_root = stridx(bufferpath, root) > -1 + endif + return b:airline_file_in_root +endfunction + +function! airline#extensions#branch#init(ext) + call airline#parts#define_function('branch', 'airline#extensions#branch#get_head') + + autocmd BufReadPost * unlet! b:airline_file_in_root endfunction