Don't blow up on vanishing HEAD

Closes #459.
This commit is contained in:
Tim Pope 2014-03-30 13:13:46 -04:00
parent d6540b2588
commit c1664de7b4
2 changed files with 7 additions and 0 deletions

View File

@ -34,6 +34,7 @@ that are part of Git repositories).
window. The following maps, which work on the cursor
line file where sensible, are provided:
<F1> this help
<C-N> next file
<C-P> previous file
<CR> |:Gedit|

View File

@ -322,6 +322,8 @@ function! s:repo_head(...) dict abort
" truncate hash to a:1 characters if we're in detached head mode
let len = a:0 ? a:1 : 0
let branch = len ? head[0:len-1] : ''
else
return ''
endif
return branch
@ -2132,6 +2134,7 @@ function! s:BufReadIndex() abort
xnoremap <buffer> <silent> p :<C-U>execute <SID>StagePatch(line("'<"),line("'>"))<CR>
nnoremap <buffer> <silent> q :<C-U>if bufnr('$') == 1<Bar>quit<Bar>else<Bar>bdelete<Bar>endif<CR>
nnoremap <buffer> <silent> R :<C-U>edit<CR>
nnoremap <buffer> <silent> <F1> :help fugitive-:Gstatus<CR>
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry
@ -2524,6 +2527,9 @@ endfunction
" Statusline {{{1
function! s:repo_head_ref() dict abort
if !filereadable(self.dir('HEAD'))
return ''
endif
return readfile(self.dir('HEAD'))[0]
endfunction