]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0356: MS-Windows: --remote may change working directory v9.1.0356
authorChristian Brabandt <cb@256bit.org>
Fri, 19 Apr 2024 13:22:33 +0000 (15:22 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 19 Apr 2024 13:26:21 +0000 (15:26 +0200)
Problem:  MS-Windows: --remote may change working directory when
          'shellslash' is set
Solution: normalize directory separators on MS-Windows

fixes: #14549
closes: #14587

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/clientserver.c
src/testdir/test_remote.vim
src/version.c

index 340add3151031d742fdb4db6d228e220dd267b33..b19cd447fa1035b6e446a012782d3cbd22f1e9ef 100644 (file)
@@ -608,7 +608,7 @@ build_drop_cmd(
 
     // Call inputsave() so that a prompt for an encryption key works.
     ga_concat(&ga, (char_u *)
-                      "<CR>:if exists('*inputsave')|call inputsave()|endif|");
+           "<CR><C-\\><C-N>:if exists('*inputsave')|call inputsave()|endif|");
     if (tabs)
        ga_concat(&ga, (char_u *)"tab ");
     ga_concat(&ga, (char_u *)"drop");
@@ -652,7 +652,13 @@ build_drop_cmd(
     //    endif
     //  endif
     ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|if haslocaldir()|");
+#ifdef MSWIN
+    // in case :set shellslash is set, need to normalize the directory separators
+    // '/' is not valid in a filename so replacing '/' by '\\' should be safe
+    ga_concat(&ga, (char_u *)"cd -|lcd -|elseif getcwd()->tr('/','\\') ==# '");
+#else
     ga_concat(&ga, (char_u *)"cd -|lcd -|elseif getcwd() ==# '");
+#endif
     ga_concat(&ga, cdp);
     ga_concat(&ga, (char_u *)"'|cd -|endif|endif<CR>");
     vim_free(cdp);
index ae931fd29123e4c22c9822a261b1c8c0a2de6bfc..1475052fe3c24caa8f096f1882c70bd7b2b9de04 100644 (file)
@@ -76,4 +76,49 @@ func Test_remote_servername()
   close
 endfunc
 
+func Test_remote_servername_shellslash()
+  " Note this test does not currently run on Windows
+  " because:
+  " 1) we cannot run the gui version of Vim inside a terminal
+  " 2) Running Windows vim.exe inside a terminal would work, but is
+  "    disabled because of the limited colors inside the default Windows
+  "    console (see CanRunVimInTerminal in term_util.vim)
+  CheckRunVimInTerminal
+  CheckMSWindows
+
+  " That is the file we want the server to open,
+  " despite the wildignore setting
+  call mkdir(expand('~/remote/'), 'pD')
+  call writefile(range(1, 20), expand('~/remote/XTEST.txt'), 'D')
+  " just a dummy file, so that the ':wq' further down is successful
+  call writefile(range(1, 20), 'Xdummy.log', 'D')
+
+  " Run Vim in a terminal and open a terminal window to run Vim in.
+  let lines =<< trim END
+    set shellslash
+    cd ~/remote
+  END
+  call writefile(lines, 'XRemoteEditing1.vim', 'D')
+  let buf = RunVimInTerminal('--servername XVIMTEST -S XRemoteEditing1.vim  Xdummy.log', {'rows': 10})
+  call TermWait(buf)
+
+  " wildignore setting should be ignored and the XVIMTEST server should now
+  " open XTEST.txt, if wildignore setting is not ignored, the server
+  " will continue with the Xdummy.log file
+  let buf2 = RunVimInTerminal('--servername XVIMTEST --remote-silent ~/remote/XTEST.txt', {'rows': 5, 'wait_for_ruler': 0})
+  " job should be no-longer running, so we can just close it
+  exe buf2 .. 'bw!'
+
+  call term_sendkeys(buf, ":pwd\<CR>")
+  call WaitForAssert({-> assert_match('remote/$', term_getline(buf, 10))}, 1000)
+  call TermWait(buf)
+  call term_sendkeys(buf, ":q!\<CR>")
+  call TermWait(buf)
+  if term_getstatus(buf) == 'running'
+    call StopVimInTerminal(buf)
+  endif
+  bw!
+  close
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index df4217dbfe5acc0ba73bd930079418fab0664a80..593ac4914afd1830a168e5a277ffda6f85def4ae 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    356,
 /**/
     355,
 /**/