aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristijan Husak <husakkristijan@gmail.com>2022-11-26 01:50:52 +0100
committerGitHub <noreply@github.com>2022-11-26 08:50:52 +0800
commit3f478547cfec72b9d3eb53efde2df45d85c44c18 (patch)
tree4f61271fd62c6c3c2fb7536aeda119c7e3f8ef9f
parent9dfbbde240fc095b856d8e0e1c670b1912ec6640 (diff)
downloadrneovim-3f478547cfec72b9d3eb53efde2df45d85c44c18.tar.gz
rneovim-3f478547cfec72b9d3eb53efde2df45d85c44c18.tar.bz2
rneovim-3f478547cfec72b9d3eb53efde2df45d85c44c18.zip
fix(startup): support .exrc or .nvimrc with init.lua (#21181)
-rw-r--r--src/nvim/main.c3
-rw-r--r--test/functional/core/startup_spec.lua64
2 files changed, 64 insertions, 3 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index a369ca0256..78b59887e7 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1919,7 +1919,8 @@ static bool do_user_initialization(void)
xfree(user_vimrc);
xfree(init_lua_path);
- return false;
+ do_exrc = p_exrc;
+ return do_exrc;
}
xfree(init_lua_path);
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index bab339e253..41596f5416 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -12,6 +12,7 @@ local eval = helpers.eval
local exec_lua = helpers.exec_lua
local feed = helpers.feed
local funcs = helpers.funcs
+local pesc = helpers.pesc
local mkdir = helpers.mkdir
local mkdir_p = helpers.mkdir_p
local nvim_prog = helpers.nvim_prog
@@ -576,7 +577,66 @@ describe('user config init', function()
eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
end)
- describe 'with explicitly provided config'(function()
+ describe('with existing .exrc in cwd', function()
+ local exrc_path = '.exrc'
+ local xstate = 'Xstate'
+
+ before_each(function()
+ write_file(init_lua_path, [[
+ vim.o.exrc = true
+ vim.g.from_exrc = 0
+ ]])
+ mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
+ write_file(exrc_path, [[
+ let g:from_exrc = 1
+ ]])
+ end)
+
+ after_each(function()
+ os.remove(exrc_path)
+ rmdir(xstate)
+ end)
+
+ it('loads .exrc #13501', function()
+ clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
+ -- The .exrc file is not trusted, and the prompt is skipped because there is no UI.
+ eq(0, eval('g:from_exrc'))
+
+ local screen = Screen.new(50, 8)
+ screen:attach()
+ funcs.termopen({nvim_prog})
+ screen:expect({ any = pesc('[i]gnore, (v)iew, (d)eny, (a)llow:') })
+ -- `i` to enter Terminal mode, `a` to allow
+ feed('ia')
+ screen:expect([[
+ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ [No Name] 0,0-1 All|
+ |
+ -- TERMINAL -- |
+ ]])
+ feed(':echo g:from_exrc<CR>')
+ screen:expect([[
+ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ [No Name] 0,0-1 All|
+ 1 |
+ -- TERMINAL -- |
+ ]])
+
+ clear{ args_rm = {'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_STATE_HOME=xstate } }
+ -- The .exrc file is now trusted.
+ eq(1, eval('g:from_exrc'))
+ end)
+ end)
+
+ describe('with explicitly provided config', function()
local custom_lua_path = table.concat({xhome, 'custom.lua'}, pathsep)
before_each(function()
write_file(custom_lua_path, [[
@@ -591,7 +651,7 @@ describe('user config init', function()
end)
end)
- describe 'VIMRC also exists'(function()
+ describe('VIMRC also exists', function()
before_each(function()
write_file(table.concat({xconfig, 'nvim', 'init.vim'}, pathsep), [[
let g:vim_rc = 1