From a37f0b9ae0f559a1a008b6420201c07409bca5b1 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Thu, 3 Apr 2014 00:54:43 +0000 Subject: [PATCH] restore original directory change detection. also resolves #474. --- autoload/airline/extensions/branch.vim | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 34dedb9..12be43f 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -2,7 +2,6 @@ " vim: et ts=2 sts=2 sw=2 let s:has_fugitive = exists('*fugitive#head') -let s:has_fugitive_detect = 0 " TODO: figure out alternative let s:has_lawrencium = exists('*lawrencium#statusline') let s:has_vcscommand = get(g:, 'airline#extensions#branch#use_vcscommand', 0) && exists('*VCSCommandGetStatusLine') @@ -10,8 +9,30 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand finish endif +let s:git_dirs = {} +function! s:get_git_branch(path) + if has_key(s:git_dirs, a:path) + return s:git_dirs[a:path] + endif + + let dir = fugitive#extract_git_dir(a:path) + if empty(dir) + let name = '' + else + try + let line = join(readfile(dir . '/HEAD')) + let name = strpart(line, 16) + catch + let name = '' + endtry + endif + + let s:git_dirs[a:path] = name + return name +endfunction + function! airline#extensions#branch#head() - if exists('b:airline_head') + if exists('b:airline_head') && !empty(b:airline_head) return b:airline_head endif @@ -20,9 +41,8 @@ function! airline#extensions#branch#head() if s:has_fugitive && !exists('b:mercurial_dir') let b:airline_head = fugitive#head() - if empty(b:airline_head) && s:has_fugitive_detect && !exists('b:git_dir') - call fugitive#detect(getcwd()) - let b:airline_head = fugitive#head() + if empty(b:airline_head) && !exists('b:git_dir') + let b:airline_head = s:get_git_branch(getcwd()) endif endif @@ -84,5 +104,5 @@ 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 - autocmd CursorHold * unlet! b:airline_head + autocmd CursorHold,ShellCmdPost,CmdwinLeave * unlet! b:airline_head endfunction