Pick sane git_dir for :Gedit from :Gstatus window

When using a :Gedit command from the :Gstatus window the git_dir was
being based on the window that was switched into in order to edit the
file. So if Fugitive switched into a window with a file from a different
Git repo (or a file with no Git repo) the :Gedit command could fail or
edit the wrong file.

Instead base the git_dir on the window from which the :Gedit command
originated.
This commit is contained in:
Trent Ogren
2012-09-21 11:30:28 -05:00
committed by Tim Pope
parent 41383131b8
commit cff78c3ab4

View File

@@ -1072,6 +1072,7 @@ endfunction
" Gedit, Gpedit, Gsplit, Gvsplit, Gtabedit, Gread {{{1
function! s:Edit(cmd,bang,...) abort
let buffer = s:buffer()
if a:cmd !~# 'read'
if &previewwindow && getbufvar('','fugitive_type') ==# 'index'
wincmd p
@@ -1091,7 +1092,7 @@ function! s:Edit(cmd,bang,...) abort
if a:bang
let args = s:gsub(a:0 ? a:1 : '', '\\@<!%(\\\\)*\zs[%#]', '\=s:buffer().expand(submatch(0))')
if a:cmd =~# 'read'
let git = s:repo().git_command()
let git = buffer.repo().git_command()
let last = line('$')
silent call s:ExecuteInTree((a:cmd ==# 'read' ? '$read' : a:cmd).'!'.git.' --no-pager '.args)
if a:cmd ==# 'read'
@@ -1102,7 +1103,7 @@ function! s:Edit(cmd,bang,...) abort
return 'redraw|echo '.string(':!'.git.' '.args)
else
let temp = resolve(tempname())
let s:temp_files[temp] = s:repo().dir()
let s:temp_files[temp] = buffer.repo().dir()
silent execute a:cmd.' '.temp
if a:cmd =~# 'pedit'
wincmd P
@@ -1124,16 +1125,16 @@ function! s:Edit(cmd,bang,...) abort
if a:0 && a:1 == ''
return ''
elseif a:0
let file = s:buffer().expand(a:1)
let file = buffer.expand(a:1)
elseif expand('%') ==# ''
let file = ':'
elseif s:buffer().commit() ==# '' && s:buffer().path('/') !~# '^/.git\>'
let file = s:buffer().path(':')
elseif buffer.commit() ==# '' && buffer.path('/') !~# '^/.git\>'
let file = buffer.path(':')
else
let file = s:buffer().path('/')
let file = buffer.path('/')
endif
try
let file = s:repo().translate(file)
let file = buffer.repo().translate(file)
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry