Use --work-tree to fix :cd side effects in :Gcommit

Closes #155
This commit is contained in:
Tim Pope 2012-03-03 03:30:27 -05:00
parent dcd79f2adb
commit 903ad4d704

View File

@ -773,13 +773,10 @@ endfunction
call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit :execute s:Commit(<q-args>)")
function! s:Commit(args) abort
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
let msgfile = s:repo().dir('COMMIT_EDITMSG')
let outfile = tempname()
let errorfile = tempname()
try
execute cd.'`=s:repo().tree()`'
if &shell =~# 'cmd'
let command = ''
let old_editor = $GIT_EDITOR
@ -787,7 +784,7 @@ function! s:Commit(args) abort
else
let command = 'env GIT_EDITOR=false '
endif
let command .= s:repo().git_command('commit').' '.a:args
let command .= s:sub(s:repo().git_command('commit'),'--git-dir','--work-tree='.s:shellesc(s:repo().tree()).' --git-dir').' '.a:args
if &shell =~# 'csh'
silent execute '!('.command.' > '.outfile.') >& '.errorfile
elseif a:args =~# '\%(^\| \)--interactive\>'
@ -843,7 +840,6 @@ function! s:Commit(args) abort
endif
call delete(outfile)
call delete(errorfile)
execute cd.'`=dir`'
call fugitive#reload_status()
endtry
endfunction