patch 8.1.0602: DirChanged is also triggered when directory didn't change
Problem: DirChanged is also triggered when the directory didn't change.
(Daniel Hahler)
Solution: Compare the current with the new directory. (closes #3697)
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c738d07..e700f2e 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9126,8 +9126,9 @@
void
ex_cd(exarg_T *eap)
{
- char_u *new_dir;
- char_u *tofree;
+ char_u *new_dir;
+ char_u *tofree;
+ int dir_differs;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
@@ -9183,7 +9184,9 @@
new_dir = NameBuff;
}
#endif
- if (new_dir == NULL || vim_chdir(new_dir))
+ dir_differs = new_dir == NULL || prev_dir == NULL
+ || STRCMP(prev_dir, new_dir) != 0;
+ if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
EMSG(_(e_failed));
else
{
@@ -9195,9 +9198,11 @@
/* Echo the new current directory if the command was typed. */
if (KeyTyped || p_verbose >= 5)
ex_pwd(eap);
- apply_autocmds(EVENT_DIRCHANGED,
- is_local_chdir ? (char_u *)"window" : (char_u *)"global",
- new_dir, FALSE, curbuf);
+
+ if (dir_differs)
+ apply_autocmds(EVENT_DIRCHANGED,
+ is_local_chdir ? (char_u *)"window" : (char_u *)"global",
+ new_dir, FALSE, curbuf);
}
vim_free(tofree);
}