restore original directory change detection. also resolves #474.

This commit is contained in:
Bailey Ling 2014-04-03 00:54:43 +00:00
parent d111e4edb3
commit a37f0b9ae0
1 changed files with 26 additions and 6 deletions

View File

@ -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