diff src/ex_docmd.c @ 15184:90ab2d3ce11d v8.1.0602

patch 8.1.0602: DirChanged is also triggered when directory didn't change commit https://github.com/vim/vim/commit/2caad3fbbdbf1486a176c9f6bfbc3d9be90e09f7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 16 15:38:02 2018 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Dec 2018 15:45:06 +0100
parents 1ef429366fd4
children 2d8c31ae1e24
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9126,8 +9126,9 @@ post_chdir(int local)
     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 @@ ex_cd(exarg_T *eap)
 	    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 @@ ex_cd(exarg_T *eap)
 	    /* 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);
     }