Merge pull request #17068 from VVKot/vim-8.2.3933

vim-patch:8.2.{3933,3973,3978,4013,4032,4048}
This commit is contained in:
Sean Dewar
2022-01-31 00:42:11 +00:00
committed by GitHub
2 changed files with 25 additions and 16 deletions

View File

@@ -7827,7 +7827,6 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
/// @return true if the directory is successfully changed. /// @return true if the directory is successfully changed.
bool changedir_func(char_u *new_dir, CdScope scope) bool changedir_func(char_u *new_dir, CdScope scope)
{ {
char_u *tofree;
char_u *pdir = NULL; char_u *pdir = NULL;
bool retval = false; bool retval = false;
@@ -7845,26 +7844,12 @@ bool changedir_func(char_u *new_dir, CdScope scope)
new_dir = pdir; new_dir = pdir;
} }
// Free the previous directory
tofree = get_prevdir(scope);
if (os_dirname(NameBuff, MAXPATHL) == OK) { if (os_dirname(NameBuff, MAXPATHL) == OK) {
pdir = vim_strsave(NameBuff); pdir = vim_strsave(NameBuff);
} else { } else {
pdir = NULL; 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. // For UNIX ":cd" means: go to home directory.
// On other systems too if 'cdhome' is set. // On other systems too if 'cdhome' is set.
#if defined(UNIX) #if defined(UNIX)
@@ -7880,12 +7865,27 @@ bool changedir_func(char_u *new_dir, CdScope scope)
bool dir_differs = new_dir == NULL || pdir == NULL bool dir_differs = new_dir == NULL || pdir == NULL
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0; || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
if (new_dir != NULL && (!dir_differs || vim_chdir(new_dir) == 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); post_chdir(scope, dir_differs);
retval = true; retval = true;
} else { } else {
emsg(_(e_failed)); emsg(_(e_failed));
xfree(pdir);
} }
xfree(tofree);
return retval; return retval;
} }

View File

@@ -44,6 +44,15 @@ func Test_cd_minus()
cd - cd -
call assert_equal(path, getcwd()) 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 " Test for :cd - without a previous directory
let lines =<< trim [SCRIPT] let lines =<< trim [SCRIPT]
call assert_fails('cd -', 'E186:') call assert_fails('cd -', 'E186:')