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,48 +662,59 @@ function! s:Blame(bang,line1,line2,count) abort
if strlen(s:buffer().commit()) == 40 if strlen(s:buffer().commit()) == 40
let cmd += [s:buffer().commit()] let cmd += [s:buffer().commit()]
else else
let cmd = ['--work-tree='.s:repo().tree()] + cmd + ['--contents', '-'] let cmd += ['--contents', '-']
endif endif
let basecmd = call(s:repo().git_command,cmd+['--',s:buffer().path()],s:repo()) let basecmd = call(s:repo().git_command,cmd+['--',s:buffer().path()],s:repo())
if a:count try
return 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g') let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
else if !s:repo().bare()
let temp = tempname().'.fugitiveblame' let dir = getcwd()
silent! exe '%write !'.basecmd.' > '.temp.' 2> '.temp execute cd.' `=s:repo().tree()`'
if v:shell_error
call s:throw(join(readfile(temp),"\n"))
endif endif
let bufnr = bufnr('') if a:count
let restore = 'call setbufvar('.bufnr.',"&scrollbind",0)' execute 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g')
if &l:wrap else
let restore .= '|call setbufvar('.bufnr.',"&wrap",1)' let temp = tempname().'.fugitiveblame'
silent! exe '%write !'.basecmd.' > '.temp.' 2> '.temp
if v:shell_error
call s:throw(join(readfile(temp),"\n"))
endif
let bufnr = bufnr('')
let restore = 'call setbufvar('.bufnr.',"&scrollbind",0)'
if &l:wrap
let restore .= '|call setbufvar('.bufnr.',"&wrap",1)'
endif
if &l:foldenable
let restore .= '|call setbufvar('.bufnr.',"&foldenable",1)'
endif
let winnr = winnr()
windo set noscrollbind
exe winnr.'wincmd w'
setlocal scrollbind nowrap nofoldenable
let top = line('w0') + &scrolloff
let current = line('.')
exe 'leftabove vsplit '.temp
let b:git_dir = git_dir
let b:fugitive_type = 'blame'
let b:fugitive_blamed_bufnr = bufnr
let b:fugitive_restore = restore
call s:Detect()
execute top
normal! zt
execute current
execute "vertical resize ".(match(getline('.'),'\s\+\d\+)')+1)
setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable filetype=fugitiveblame
nnoremap <buffer> <silent> q :bdelete<CR>
nnoremap <buffer> <silent> <CR> :exe <SID>BlameJump()<CR>
nnoremap <buffer> <silent> o :<C-U>exe <SID>Edit((&splitbelow ? "botright" : "topleft")." split", matchstr(getline('.'),'\x\+'))<CR>
nnoremap <buffer> <silent> O :<C-U>exe <SID>Edit("tabedit", matchstr(getline('.'),'\x\+'))<CR>
syncbind
endif endif
if &l:foldenable finally
let restore .= '|call setbufvar('.bufnr.',"&foldenable",1)' if exists('l:dir')
execute cd.' `=dir`'
endif endif
let winnr = winnr() endtry
windo set noscrollbind
exe winnr.'wincmd w'
setlocal scrollbind nowrap nofoldenable
let top = line('w0') + &scrolloff
let current = line('.')
exe 'leftabove vsplit '.temp
let b:git_dir = git_dir
let b:fugitive_type = 'blame'
let b:fugitive_blamed_bufnr = bufnr
let b:fugitive_restore = restore
call s:Detect()
execute top
normal! zt
execute current
execute "vertical resize ".(match(getline('.'),'\s\+\d\+)')+1)
setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable filetype=fugitiveblame
nnoremap <buffer> <silent> q :bdelete<CR>
nnoremap <buffer> <silent> <CR> :exe <SID>BlameJump()<CR>
nnoremap <buffer> <silent> o :<C-U>exe <SID>Edit((&splitbelow ? "botright" : "topleft")." split", matchstr(getline('.'),'\x\+'))<CR>
nnoremap <buffer> <silent> O :<C-U>exe <SID>Edit("tabedit", matchstr(getline('.'),'\x\+'))<CR>
syncbind
endif
return '' return ''
catch /^fugitive:/ catch /^fugitive:/
return 'echoerr v:errmsg' return 'echoerr v:errmsg'