From ea6db3c7df7671584df0a37a2436a919332d0b7c Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 20 Dec 2018 22:04:09 +0100 Subject: [PATCH] Improve directory changing On Windows, Vim and Nvim can't work with mklink'ed paths. Issue an error message and bail out before starting the actual job when the directory can't be changed. Fixes https://github.com/mhinz/vim-signify/issues/279 --- autoload/sy/repo.vim | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 7a5b3a7..87fd287 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -73,13 +73,23 @@ function! sy#repo#get_diff_start(vcs) abort endif let [cmd, options] = s:initialize_job(a:vcs) + let [cwd, chdir] = sy#util#chdir() call sy#verbose(printf('CMD: %s | CWD: %s', string(cmd), b:sy.info.dir), a:vcs) + + try + execute chdir fnameescape(b:sy.info.dir) + catch + echohl ErrorMsg + echomsg 'signify: Switching Changing failed: '. b:sy.info.dir + echohl NONE + return + endtry let b:sy_job_id_{a:vcs} = jobstart(cmd, extend(options, { - \ 'cwd': b:sy.info.dir, \ 'on_stdout': function('s:callback_nvim_stdout'), \ 'on_exit': function('s:callback_nvim_exit'), \ })) + execute chdir fnameescape(cwd) " Newer Vim elseif has('patch-7.4.1967') @@ -90,19 +100,23 @@ function! sy#repo#get_diff_start(vcs) abort let [cmd, options] = s:initialize_job(a:vcs) let [cwd, chdir] = sy#util#chdir() + call sy#verbose(printf('CMD: %s | CWD: %s', string(cmd), getcwd()), a:vcs) + try execute chdir fnameescape(b:sy.info.dir) - call sy#verbose(printf('CMD: %s | CWD: %s', string(cmd), getcwd()), a:vcs) - let opts = { - \ 'in_io': 'null', - \ 'out_cb': function('s:callback_vim_stdout', options), - \ 'close_cb': function('s:callback_vim_close', options), - \ } - let b:sy_job_id_{a:vcs} = job_start(cmd, opts) catch - finally - execute chdir fnameescape(cwd) + echohl ErrorMsg + echomsg 'signify: Changing directory failed: '. b:sy.info.dir + echohl NONE + return endtry + let opts = { + \ 'in_io': 'null', + \ 'out_cb': function('s:callback_vim_stdout', options), + \ 'close_cb': function('s:callback_vim_close', options), + \ } + let b:sy_job_id_{a:vcs} = job_start(cmd, opts) + execute chdir fnameescape(cwd) " Older Vim else