File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,18 @@ function! go#tool#FilterValids(items) abort
162
162
endfunction
163
163
164
164
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, err] = go#util#Exec ([" false" ])
174
+ return ' '
175
+ endif
176
+
165
177
let old_gopath = $GOPATH
166
178
let old_goroot = $GOROOT
167
179
let $GOPATH = go#path#Detect ()
Original file line number Diff line number Diff line change
1
+ func ! Test_ExecuteInDir () abort
2
+ let l: tmp = gotest#write_file (' a/a.go' , [' package a' ])
3
+ try
4
+ let l: out = go#tool#ExecuteInDir (" pwd" )
5
+ call assert_equal (l: tmp . " /src/a\n " , l: out )
6
+ finally
7
+ call delete (l: tmp , ' rf' )
8
+ endtry
9
+ endfunc
10
+
11
+ func ! Test_ExecuteInDir_nodir () abort
12
+ let l: tmp = go#util#tempdir (" executeindir" )
13
+ exe ' :e ' . l: tmp . ' /new-dir/a'
14
+
15
+ try
16
+ let l: out = go#tool#ExecuteInDir (" pwd" )
17
+ call assert_equal (' ' , l: out )
18
+ finally
19
+ call delete (l: tmp , ' rf' )
20
+ endtry
21
+ endfunc
22
+
23
+ " vim: sw = 2 ts = 2 et
You can’t perform that action at this time.
0 commit comments