Skip to content

Commit 2349b46

Browse files
committed
fix: Fix session relying on getcwd without specifying global (-1)
Fixes #45
1 parent 9c3f977 commit 2349b46

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lua/auto-session/init.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ local function suppress_session(session_dir)
173173

174174
-- If session_dir is set, use that otherwise use cwd
175175
-- session_dir will be set when loading a session from a directory at lauch (i.e. from argv)
176-
local cwd = session_dir or vim.fn.getcwd()
176+
local cwd = session_dir or vim.fn.getcwd(-1)
177177

178178
if Lib.find_matching_directory(cwd, dirs) then
179179
Lib.logger.debug "suppress_session found a match, suppressing"
@@ -190,7 +190,7 @@ local function is_allowed_dir()
190190
end
191191

192192
local dirs = Config.allowed_dirs or {}
193-
local cwd = vim.fn.getcwd()
193+
local cwd = vim.fn.getcwd(-1)
194194

195195
if Lib.find_matching_directory(cwd, dirs) then
196196
Lib.logger.debug "is_allowed_dir found a match, allowing"
@@ -209,7 +209,7 @@ end
209209
---@return string Returns the escaped version of the name with .vim appended.
210210
local function get_session_file_name(session_name, legacy)
211211
if not session_name or session_name == "" then
212-
session_name = vim.fn.getcwd()
212+
session_name = vim.fn.getcwd(-1)
213213
Lib.logger.debug("get_session_file_name no session_name, using cwd: " .. session_name)
214214

215215
local git_branch_name = get_git_branch_name()
@@ -279,13 +279,13 @@ end
279279
---unless a session for the current working directory exists.
280280
---@return boolean True if a session exists for the cwd
281281
function AutoSession.session_exists_for_cwd()
282-
local session_file = get_session_file_name(vim.fn.getcwd())
282+
local session_file = get_session_file_name(vim.fn.getcwd(-1))
283283
if vim.fn.filereadable(AutoSession.get_root_dir() .. session_file) ~= 0 then
284284
return true
285285
end
286286

287287
-- Check legacy sessions
288-
session_file = get_session_file_name(vim.fn.getcwd(), true)
288+
session_file = get_session_file_name(vim.fn.getcwd(-1), true)
289289
return vim.fn.filereadable(AutoSession.get_root_dir() .. session_file) ~= 0
290290
end
291291

@@ -482,7 +482,7 @@ function AutoSession.auto_restore_session_at_vim_enter()
482482

483483
-- We failed to load a session for the other directory. Unless session name matches cwd, we don't
484484
-- want to enable autosaving since it might replace the session for the cwd
485-
if vim.fn.getcwd() ~= session_name then
485+
if vim.fn.getcwd(-1) ~= session_name then
486486
Lib.logger.debug "Not enabling autosave because launch argument didn't load session and doesn't match cwd"
487487
Config.auto_save = false
488488
end

0 commit comments

Comments
 (0)