]> granicus.if.org Git - vim/commitdiff
patch 8.2.3468: problem with :cd when editing file in non-existent directory v8.2.3468
authorBram Moolenaar <Bram@vim.org>
Sun, 3 Oct 2021 18:29:48 +0000 (19:29 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 3 Oct 2021 18:29:48 +0000 (19:29 +0100)
Problem:    Problem with :cd when editing file in non-existent directory. (Yee
            Cheng Chin)
Solution:   Prepend the current directory to get the full path. (closes #8903)

src/os_unix.c
src/testdir/test_cd.vim
src/version.c

index a3e5430ef915b5da1d09036c6b98a7e38b8c6a31..d192b6bcfab059c6712b3e3f0cddd5f7dd3d13fa 100644 (file)
@@ -2647,7 +2647,15 @@ mch_FullName(
                {
                    vim_strncpy(buf, fname, p - fname);
                    if (mch_chdir((char *)buf))
-                       retval = FAIL;
+                   {
+                       // Path does not exist (yet).  For a full path fail,
+                       // will use the path as-is.  For a relative path use
+                       // the current directory and append the file name.
+                       if (mch_isFullName(fname))
+                           retval = FAIL;
+                       else
+                           p = NULL;
+                   }
                    else if (*p == '/')
                        fname = p + 1;
                    else
index 8eda44aff265761ab506a4303e643d6b004ac952..bcca2f8e7cfceb60f1cddf9cab82d78e4d30be24 100644 (file)
@@ -208,4 +208,21 @@ func Test_cd_completion()
   call delete('XComplFile')
 endfunc
 
+func Test_cd_unknown_dir()
+  call mkdir('Xa')
+  cd Xa
+  call writefile(['text'], 'Xb.txt')
+  edit Xa/Xb.txt
+  let first_buf = bufnr()
+  cd ..
+  edit
+  call assert_equal(first_buf, bufnr())
+  edit Xa/Xb.txt
+  call assert_notequal(first_buf, bufnr())
+
+  bwipe!
+  exe "bwipe! " .. first_buf
+  call delete('Xa', 'rf')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 410776742ffc41c8187b12fea3b37929721086a0..00ede81abec1cba6b8e3370f0341933d864165a0 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3468,
 /**/
     3467,
 /**/