Fix :Gblame when run from a subdirectory

This commit is contained in:
Tim Pope 2009-10-12 21:48:16 -04:00
parent 61698761e5
commit a5e10c932d

View File

@ -662,11 +662,17 @@ function! s:Blame(bang,line1,line2,count) abort
if strlen(s:buffer().commit()) == 40
let cmd += [s:buffer().commit()]
else
let cmd = ['--work-tree='.s:repo().tree()] + cmd + ['--contents', '-']
let cmd += ['--contents', '-']
endif
let basecmd = call(s:repo().git_command,cmd+['--',s:buffer().path()],s:repo())
try
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
if !s:repo().bare()
let dir = getcwd()
execute cd.' `=s:repo().tree()`'
endif
if a:count
return 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g')
execute 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g')
else
let temp = tempname().'.fugitiveblame'
silent! exe '%write !'.basecmd.' > '.temp.' 2> '.temp
@ -704,6 +710,11 @@ function! s:Blame(bang,line1,line2,count) abort
nnoremap <buffer> <silent> O :<C-U>exe <SID>Edit("tabedit", matchstr(getline('.'),'\x\+'))<CR>
syncbind
endif
finally
if exists('l:dir')
execute cd.' `=dir`'
endif
endtry
return ''
catch /^fugitive:/
return 'echoerr v:errmsg'