aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-10-17 22:04:53 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-10-17 22:04:53 +0800
commit57651df9c11740a24a2f71801d9b7b81b894d601 (patch)
treefe98c51fc2a7a9eca057ca112e5e16048f2eed0e
parente91dee5c21ffca22ac821336ad23bce6339b5f7c (diff)
downloadrneovim-57651df9c11740a24a2f71801d9b7b81b894d601.tar.gz
rneovim-57651df9c11740a24a2f71801d9b7b81b894d601.tar.bz2
rneovim-57651df9c11740a24a2f71801d9b7b81b894d601.zip
vim-patch:8.1.0604: autocommand test fails on MS-Windows
Problem: Autocommand test fails on MS-Windows. Solution: Use pathcmp() instead of strcmp() to check if a directory differs. https://github.com/vim/vim/commit/9eb76af451ddd8eaad0cd5dd629f18c4f4035171
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/file_search.c19
-rw-r--r--src/nvim/window.c5
-rw-r--r--test/functional/autocmd/dirchanged_spec.lua55
4 files changed, 70 insertions, 11 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index b81aab9ffe..cc30557ead 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -7811,7 +7811,7 @@ void ex_cd(exarg_T *eap)
break;
}
- bool dir_differs = prev_dir == NULL || STRCMP(prev_dir, new_dir) != 0;
+ bool dir_differs = prev_dir == NULL || pathcmp((char *)prev_dir, (char *)new_dir, -1) != 0;
if (dir_differs && vim_chdir(new_dir)) {
EMSG(_(e_failed));
} else {
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index e7c4785beb..22c7b35fa9 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1620,6 +1620,13 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
abort();
}
+#ifdef BACKSLASH_IN_FILENAME
+ char new_dir_buf[MAXPATHL];
+ STRCPY(new_dir_buf, new_dir);
+ slash_adjust(new_dir_buf);
+ new_dir = new_dir_buf;
+#endif
+
tv_dict_add_str(dict, S_LEN("scope"), buf); // -V614
tv_dict_add_str(dict, S_LEN("cwd"), new_dir);
tv_dict_add_bool(dict, S_LEN("changed_window"), cause == kCdCauseWindow);
@@ -1659,14 +1666,10 @@ int vim_chdirfile(char_u *fname, CdCause cause)
NameBuff[0] = NUL;
}
- if (os_chdir(dir) != 0) {
- return FAIL;
- }
-
-#ifdef BACKSLASH_IN_FILENAME
- slash_adjust((char_u *)dir);
-#endif
- if (cause != kCdCauseOther && !strequal(dir, (char *)NameBuff)) {
+ if (cause != kCdCauseOther && pathcmp(dir, (char *)NameBuff, -1) != 0) {
+ if (os_chdir(dir) != 0) {
+ return FAIL;
+ }
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index a7470889b3..49d7c9c9f5 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -23,6 +23,7 @@
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/hashtab.h"
#include "nvim/main.h"
#include "nvim/mark.h"
@@ -4540,7 +4541,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
}
}
if (os_chdir(new_dir) == 0) {
- if (!p_acd && !strequal(new_dir, cwd)) {
+ if (!p_acd && pathcmp(new_dir, cwd, -1) != 0) {
do_autocmd_dirchanged(new_dir, curwin->w_localdir
? kCdScopeWindow : kCdScopeTab, kCdCauseWindow);
}
@@ -4550,7 +4551,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
// Window doesn't have a local directory and we are not in the global
// directory: Change to the global directory.
if (os_chdir((char *)globaldir) == 0) {
- if (!p_acd && !strequal((char *)globaldir, cwd)) {
+ if (!p_acd && pathcmp((char *)globaldir, cwd, -1) != 0) {
do_autocmd_dirchanged((char *)globaldir, kCdScopeGlobal, kCdCauseWindow);
}
}
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua
index 2e1aff3914..ce3b2e8d3e 100644
--- a/test/functional/autocmd/dirchanged_spec.lua
+++ b/test/functional/autocmd/dirchanged_spec.lua
@@ -6,6 +6,7 @@ local command = h.command
local eq = h.eq
local eval = h.eval
local request = h.request
+local iswin = h.iswin
describe('autocmd DirChanged', function()
local curdir = string.gsub(lfs.currentdir(), '\\', '/')
@@ -14,6 +15,11 @@ describe('autocmd DirChanged', function()
curdir .. '/Xtest-functional-autocmd-dirchanged.dir2',
curdir .. '/Xtest-functional-autocmd-dirchanged.dir3',
}
+ local win_dirs = {
+ curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR1',
+ curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR2',
+ curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3',
+ }
setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end)
teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end)
@@ -122,6 +128,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(1, eval('g:cdcount'))
+ if iswin() then
+ command('lcd '..win_dirs[1])
+ eq({}, eval('g:ev'))
+ eq(1, eval('g:cdcount'))
+ end
+
command('tcd '..dirs[2])
eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev'))
eq(2, eval('g:cdcount'))
@@ -130,6 +142,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(2, eval('g:cdcount'))
+ if iswin() then
+ command('tcd '..win_dirs[2])
+ eq({}, eval('g:ev'))
+ eq(2, eval('g:cdcount'))
+ end
+
command('cd '..dirs[3])
eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev'))
eq(3, eval('g:cdcount'))
@@ -138,6 +156,12 @@ describe('autocmd DirChanged', function()
eq({}, eval('g:ev'))
eq(3, eval('g:cdcount'))
+ if iswin() then
+ command('cd '..win_dirs[3])
+ eq({}, eval('g:ev'))
+ eq(3, eval('g:cdcount'))
+ end
+
command('set autochdir')
command('split '..dirs[1]..'/foo')
@@ -147,6 +171,12 @@ describe('autocmd DirChanged', function()
command('split '..dirs[1]..'/bar')
eq({}, eval('g:ev'))
eq(4, eval('g:cdcount'))
+
+ if iswin() then
+ command('split '..win_dirs[1]..'/baz')
+ eq({}, eval('g:ev'))
+ eq(4, eval('g:cdcount'))
+ end
end)
it("is triggered by switching to win/tab with different CWD #6054", function()
@@ -174,6 +204,31 @@ describe('autocmd DirChanged', function()
eq(9, eval('g:cdcount'))
command('tabnext') -- tab 2 (has the *same* CWD)
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+
+ if iswin() then
+ command('tabnew') -- tab 3
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tcd '..win_dirs[3])
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabnext') -- tab 1
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabprevious') -- tab 3
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabprevious') -- tab 2
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabprevious') -- tab 1
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('lcd '..win_dirs[3]) -- window 3
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabnext') -- tab 2
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabnext') -- tab 3
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabnext') -- tab 1
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ command('tabprevious') -- tab 3
+ eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
+ end
end)
it('is triggered by nvim_set_current_dir()', function()