aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVVKot <volodymyr.kot.ua@gmail.com>2022-01-13 05:51:16 +0000
committerSean Dewar <seandewar@users.noreply.github.com>2022-01-31 00:07:32 +0000
commitf19921be0cba1a38bd15f2b3a2d41992fcb5553b (patch)
tree6394c2d044bf4c7f85fe8f0f31cfbb7ff9d46c6c /src
parenta28a9aec635676873e18e1ffe8d2334dd00a7ad3 (diff)
downloadrneovim-f19921be0cba1a38bd15f2b3a2d41992fcb5553b.tar.gz
rneovim-f19921be0cba1a38bd15f2b3a2d41992fcb5553b.tar.bz2
rneovim-f19921be0cba1a38bd15f2b3a2d41992fcb5553b.zip
vim-patch:8.2.3933: after ":cd" fails ":cd -" is incorrect
Problem: After ":cd" fails ":cd -" is incorrect. Solution: Set the previous directory only after successfully changing directory. (Richard Doty, closes vim/vim#9419, closes vim/vim#8983) https://github.com/vim/vim/commit/3d0abad5bf4fe125e219f1b56c4e8200cb900e2a Adjust the test's error message check due to missing patch vim-patch:8.2.3973: tiny build fails Problem: Tiny build fails. Solution: Adjust #ifdefs https://github.com/vim/vim/commit/0f7a5e758c5d8be2d8f1ab4a145d1636a36d18b2 vim-patch:8.2.3978: build error when using dynamycally loaded Python 3 Problem: Build error when using dynamycally loaded Python 3. Solution: Adjust #ifdef. https://github.com/vim/vim/commit/6b1a99dfe33cf5a1d7f82febd81face85ac1b8a6 vim-patch:8.2.4013: build failure without the spell feature Problem: Build failure without the spell feature. Solution: Adjust #ifdefs. https://github.com/vim/vim/commit/e60b3c47d701e73ecbadb1b9a12bf82010cadae8 vim-patch:8.2.4032: ATTRIBUTE_NORETURN is not needed Problem: ATTRIBUTE_NORETURN is not needed. Solution: Use NORETURN(). (Ozaki Kiichi, closes vim/vim#9487) https://github.com/vim/vim/commit/e12406526a24768e6121450112eb2f9f92445ac5 vim-patch:8.2.4048: gcc complains about use of "%p" in printf Problem: gcc complains about use of "%p" in printf. Solution: Add (void *) typecast. (Dominique Pellé, closes vim/vim#9494) https://github.com/vim/vim/commit/c14f667626ba677a767d474324306e39096dc43e
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_docmd.c32
-rw-r--r--src/nvim/testdir/test_cd.vim9
2 files changed, 25 insertions, 16 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index c30d58a8eb..4325ef7229 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -7825,7 +7825,6 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
/// @return true if the directory is successfully changed.
bool changedir_func(char_u *new_dir, CdScope scope)
{
- char_u *tofree;
char_u *pdir = NULL;
bool retval = false;
@@ -7843,26 +7842,12 @@ bool changedir_func(char_u *new_dir, CdScope scope)
new_dir = pdir;
}
- // Free the previous directory
- tofree = get_prevdir(scope);
-
if (os_dirname(NameBuff, MAXPATHL) == OK) {
pdir = vim_strsave(NameBuff);
} else {
pdir = NULL;
}
- switch (scope) {
- case kCdScopeTabpage:
- curtab->tp_prevdir = pdir;
- break;
- case kCdScopeWindow:
- curwin->w_prevdir = pdir;
- break;
- default:
- prev_dir = pdir;
- }
-
// For UNIX ":cd" means: go to home directory.
// On other systems too if 'cdhome' is set.
#if defined(UNIX)
@@ -7878,12 +7863,27 @@ bool changedir_func(char_u *new_dir, CdScope scope)
bool 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) == 0)) {
+ char_u **pp;
+
+ switch (scope) {
+ case kCdScopeTabpage:
+ pp = &curtab->tp_prevdir;
+ break;
+ case kCdScopeWindow:
+ pp = &curwin->w_prevdir;
+ break;
+ default:
+ pp = &prev_dir;
+ }
+ xfree(*pp);
+ *pp = pdir;
+
post_chdir(scope, dir_differs);
retval = true;
} else {
emsg(_(e_failed));
+ xfree(pdir);
}
- xfree(tofree);
return retval;
}
diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim
index 76a2620be0..c364babd65 100644
--- a/src/nvim/testdir/test_cd.vim
+++ b/src/nvim/testdir/test_cd.vim
@@ -44,6 +44,15 @@ func Test_cd_minus()
cd -
call assert_equal(path, getcwd())
+ " Test for :cd - after a failed :cd
+ " v8.2.1183 is not ported yet
+ " call assert_fails('cd /nonexistent', 'E344:')
+ call assert_fails('cd /nonexistent', 'E472:')
+ 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:')