From cff78c3ab4605d490e6be8d8af02f1e7efd25c95 Mon Sep 17 00:00:00 2001 From: Trent Ogren Date: Fri, 21 Sep 2012 11:30:28 -0500 Subject: [PATCH] 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. --- plugin/fugitive.vim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index c3a9c56..d913bea 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -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 : '', '\\@' - 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