Patch 8.2.3933
Problem: After ":cd" fails ":cd -" is incorrect.
Solution: Set the previous directory only after successfully changing
directory. (Richard Doty, closes #9419, closes #8983)
Files: src/ex_docmd.c, src/testdir/test_cd.vim
*** ../vim-8.2.3932/src/ex_docmd.c 2021-12-28 20:59:51.975937080 +0000
--- src/ex_docmd.c 2021-12-29 14:35:55.758493422 +0000
***************
*** 7359,7365 ****
int forceit,
cdscope_T scope)
{
- char_u *tofree;
char_u *pdir = NULL;
int dir_differs;
int retval = FALSE;
--- 7359,7364 ----
***************
*** 7385,7404 ****
new_dir = pdir;
}
- // Free the previous directory
- tofree = get_prevdir(scope);
-
// Save current directory for next ":cd -"
if (mch_dirname(NameBuff, MAXPATHL) == OK)
pdir = vim_strsave(NameBuff);
else
pdir = NULL;
- if (scope == CDSCOPE_WINDOW)
- curwin->w_prevdir = pdir;
- else if (scope == CDSCOPE_TABPAGE)
- curtab->tp_prevdir = pdir;
- else
- prev_dir = pdir;
// For UNIX ":cd" means: go to home directory.
// On other systems too if 'cdhome' is set.
--- 7384,7394 ----
***************
*** 7425,7434 ****
--- 7415,7437 ----
dir_differs = new_dir == NULL || pdir == NULL
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
+ {
emsg(_(e_failed));
+ vim_free(pdir);
+ }
else
{
char_u *acmd_fname;
+ char_u **pp;
+
+ if (scope == CDSCOPE_WINDOW)
+ pp = &curwin->w_prevdir;
+ else if (scope == CDSCOPE_TABPAGE)
+ pp = &curtab->tp_prevdir;
+ else
+ pp = &prev_dir;
+ vim_free(*pp);
+ *pp = pdir;
post_chdir(scope);
***************
*** 7445,7451 ****
}
retval = TRUE;
}
- vim_free(tofree);
return retval;
}
--- 7448,7453 ----
***************
*** 7565,7573 ****
# endif
if (hide_cursor)
! cursor_sleep();
else
! cursor_on();
out_flush_cursor(FALSE, FALSE);
while (!got_int && done < msec)
--- 7567,7575 ----
# endif
if (hide_cursor)
! cursor_sleep();
else
! cursor_on();
out_flush_cursor(FALSE, FALSE);
while (!got_int && done < msec)
***************
*** 7619,7625 ****
(void)vpeekc();
if (hide_cursor)
! cursor_unsleep();
}
/*
--- 7621,7627 ----
(void)vpeekc();
if (hide_cursor)
! cursor_unsleep();
}
/*
*** ../vim-8.2.3932/src/testdir/test_cd.vim 2021-12-04 15:12:36.957739980 +0000
--- src/testdir/test_cd.vim 2021-12-29 14:27:35.955026205 +0000
***************
*** 44,49 ****
--- 44,56 ----
cd -
call assert_equal(path, getcwd())
+ " Test for :cd - after a failed :cd
+ call assert_fails('cd /nonexistent', 'E344:')
+ call assert_equal(path, getcwd())
+ cd -
+ call assert_equal(path_dotdot, getcwd())
+ cd -
+
" Test for :cd - without a previous directory
let lines =<< trim [SCRIPT]
call assert_fails('cd -', 'E186:')
*** ../vim-8.2.3932/src/version.c 2021-12-29 14:09:28.636663343 +0000
--- src/version.c 2021-12-29 14:29:37.478914721 +0000
***************
*** 751,752 ****
--- 751,754 ----
{ /* Add new patch number below this line */
+ /**/
+ 3933,
/**/
--
The coffee just wasn't strong enough to defend itself -- Tom Waits
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///