]> granicus.if.org Git - vim/commitdiff
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used v8.2.3618
authorBram Moolenaar <Bram@vim.org>
Thu, 18 Nov 2021 20:47:31 +0000 (20:47 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 18 Nov 2021 20:47:31 +0000 (20:47 +0000)
Problem:    getcwd() is unclear about how 'autochdir' is used.
Solution:   Update the help for getcwd().  Without any arguments always return
            the actual current directory. (closes #9142)

runtime/doc/eval.txt
src/filepath.c
src/testdir/test_cd.vim
src/version.c

index e29b56411b1c401c8d856428215adc34380bbc3f..593dcb5177b9ffc4cfc124f2667df97c10287d14 100644 (file)
@@ -5757,7 +5757,7 @@ getcursorcharpos([{winid}])
 <                                                      *getcwd()*
 getcwd([{winnr} [, {tabnr}]])
                The result is a String, which is the name of the current
-               working directory.
+               working directory.  'autochdir' is ignored.
 
                With {winnr} return the local current directory of this window
                in the current tab page.  {winnr} can be the window number or
@@ -5770,8 +5770,8 @@ getcwd([{winnr} [, {tabnr}]])
                the working directory of the tabpage.
                If {winnr} is zero use the current window, if {tabnr} is zero
                use the current tabpage.
-               Without any arguments, return the working directory of the
-               current window.
+               Without any arguments, return the actual working directory of
+               the current window.
                Return an empty string if the arguments are invalid.
 
                Examples: >
index 74ee2ec15a458f875834aaedd81cdcc2415d6b2d..f4bddf859c0f6770473fb7026e60b845ab9cf632 100644 (file)
@@ -1102,13 +1102,15 @@ f_getcwd(typval_T *argvars, typval_T *rettv)
     else
        wp = find_tabwin(&argvars[0], &argvars[1], &tp);
 
-    if (wp != NULL && wp->w_localdir != NULL)
+    if (wp != NULL && wp->w_localdir != NULL
+                                          && argvars[0].v_type != VAR_UNKNOWN)
        rettv->vval.v_string = vim_strsave(wp->w_localdir);
-    else if (tp != NULL && tp->tp_localdir != NULL)
+    else if (tp != NULL && tp->tp_localdir != NULL
+                                          && argvars[0].v_type != VAR_UNKNOWN)
        rettv->vval.v_string = vim_strsave(tp->tp_localdir);
     else if (wp != NULL || tp != NULL || global)
     {
-       if (globaldir != NULL)
+       if (globaldir != NULL && argvars[0].v_type != VAR_UNKNOWN)
            rettv->vval.v_string = vim_strsave(globaldir);
        else
        {
index bcca2f8e7cfceb60f1cddf9cab82d78e4d30be24..81ed491ea59f6be9614e472dcd7a5edf6719bab0 100644 (file)
@@ -225,4 +225,23 @@ func Test_cd_unknown_dir()
   call delete('Xa', 'rf')
 endfunc
 
+func Test_getcwd_actual_dir()
+  let startdir = getcwd()
+  call mkdir('Xactual')
+  call test_autochdir()
+  set autochdir
+  edit Xactual/file.txt
+  call assert_match('testdir.Xactual$', getcwd())
+  lcd ..
+  call assert_match('testdir$', getcwd())
+  edit
+  call assert_match('testdir.Xactual$', getcwd())
+  call assert_match('testdir$', getcwd(win_getid()))
+
+  set noautochdir
+  bwipe!
+  call chdir(startdir)
+  call delete('Xactual', 'rf')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 69193a626a43a68033bf7a0bcfcf1117b1f847ab..6125df90cdfb6ffb6a9a03f7d77cf52dc34e4a0e 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3618,
 /**/
     3617,
 /**/