forked from aniani/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 #9419, closes #8983)
This commit is contained in:
committed by
Bram Moolenaar
parent
264d3ddac0
commit
3d0abad5bf
@@ -7359,7 +7359,6 @@ changedir_func(
|
|||||||
int forceit,
|
int forceit,
|
||||||
cdscope_T scope)
|
cdscope_T scope)
|
||||||
{
|
{
|
||||||
char_u *tofree;
|
|
||||||
char_u *pdir = NULL;
|
char_u *pdir = NULL;
|
||||||
int dir_differs;
|
int dir_differs;
|
||||||
int retval = FALSE;
|
int retval = FALSE;
|
||||||
@@ -7385,20 +7384,11 @@ changedir_func(
|
|||||||
new_dir = pdir;
|
new_dir = pdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the previous directory
|
|
||||||
tofree = get_prevdir(scope);
|
|
||||||
|
|
||||||
// Save current directory for next ":cd -"
|
// Save current directory for next ":cd -"
|
||||||
if (mch_dirname(NameBuff, MAXPATHL) == OK)
|
if (mch_dirname(NameBuff, MAXPATHL) == OK)
|
||||||
pdir = vim_strsave(NameBuff);
|
pdir = vim_strsave(NameBuff);
|
||||||
else
|
else
|
||||||
pdir = NULL;
|
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.
|
// For UNIX ":cd" means: go to home directory.
|
||||||
// On other systems too if 'cdhome' is set.
|
// On other systems too if 'cdhome' is set.
|
||||||
@@ -7425,10 +7415,23 @@ changedir_func(
|
|||||||
dir_differs = new_dir == NULL || pdir == NULL
|
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)))
|
if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
|
||||||
|
{
|
||||||
emsg(_(e_failed));
|
emsg(_(e_failed));
|
||||||
|
vim_free(pdir);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char_u *acmd_fname;
|
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);
|
post_chdir(scope);
|
||||||
|
|
||||||
@@ -7445,7 +7448,6 @@ changedir_func(
|
|||||||
}
|
}
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
}
|
}
|
||||||
vim_free(tofree);
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -7565,9 +7567,9 @@ do_sleep(long msec, int hide_cursor)
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (hide_cursor)
|
if (hide_cursor)
|
||||||
cursor_sleep();
|
cursor_sleep();
|
||||||
else
|
else
|
||||||
cursor_on();
|
cursor_on();
|
||||||
|
|
||||||
out_flush_cursor(FALSE, FALSE);
|
out_flush_cursor(FALSE, FALSE);
|
||||||
while (!got_int && done < msec)
|
while (!got_int && done < msec)
|
||||||
@@ -7619,7 +7621,7 @@ do_sleep(long msec, int hide_cursor)
|
|||||||
(void)vpeekc();
|
(void)vpeekc();
|
||||||
|
|
||||||
if (hide_cursor)
|
if (hide_cursor)
|
||||||
cursor_unsleep();
|
cursor_unsleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -44,6 +44,13 @@ func Test_cd_minus()
|
|||||||
cd -
|
cd -
|
||||||
call assert_equal(path, getcwd())
|
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
|
" 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:')
|
||||||
|
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3933,
|
||||||
/**/
|
/**/
|
||||||
3932,
|
3932,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user