Skip to content

Commit c5ff65f

Browse files
committed
eliminate errors when trying to run a command in a directory that does not exist
1 parent 0643e9e commit c5ff65f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

autoload/go/tool.vim

+12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ function! go#tool#FilterValids(items) abort
162162
endfunction
163163

164164
function! go#tool#ExecuteInDir(cmd) abort
165+
" Verify that the directory actually exists. If the directory does not
166+
" exist, then assume that the a:cmd should not be executed. Callers expect
167+
" to check v:shell_error (via go#util.ShellError()), so execute a command
168+
" that will return an error as if a:cmd was run and exited with an error.
169+
" This helps avoid errors when working with plugins that use virtual files
170+
" that don't actually exist on the file system (e.g. vim-fugitive's
171+
" GitDiff).
172+
if !isdirectory(expand("%:p:h"))
173+
let out = go#util#System("exit 1")
174+
return out
175+
endif
176+
165177
let old_gopath = $GOPATH
166178
let old_goroot = $GOROOT
167179
let $GOPATH = go#path#Detect()

0 commit comments

Comments
 (0)