Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #286 for legacy session file names #345

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ end
---@return boolean True if a session exists for the cwd
function AutoSession.session_exists_for_cwd()
local session_file = get_session_file_name(vim.fn.getcwd())
if vim.fn.filereadable(AutoSession.get_root_dir() .. session_file) ~= 0 then
return true
end

-- Check legacy sessions
local session_file = get_session_file_name(vim.fn.getcwd(), true)
return vim.fn.filereadable(AutoSession.get_root_dir() .. session_file) ~= 0
end

Expand Down
1 change: 1 addition & 0 deletions tests/cmds_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("The default config", function()
end)

it("can save a session for the cwd", function()
assert.False(as.session_exists_for_cwd())
vim.cmd("e " .. TL.test_file)

vim.cmd "SessionSave"
Expand Down
5 changes: 5 additions & 0 deletions tests/legacy_file_names_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ describe("Legacy file name support", function()

-- save a default session in new format
as.SaveSession()

assert.True(as.session_exists_for_cwd())
assert.equals(1, vim.fn.filereadable(TL.default_session_path))
assert.equals(1, vim.fn.filereadable(default_extra_cmds_path))

vim.loop.fs_rename(TL.default_session_path, TL.default_session_path_legacy)
vim.loop.fs_rename(default_extra_cmds_path, legacy_extra_cmds_path)

print(TL.default_session_path_legacy)
assert.True(as.session_exists_for_cwd())
assert.equals(1, vim.fn.filereadable(TL.default_session_path_legacy))
assert.equals(0, vim.fn.filereadable(TL.default_session_path))
assert.equals(1, vim.fn.filereadable(legacy_extra_cmds_path))
Expand All @@ -54,6 +57,8 @@ describe("Legacy file name support", function()
-- and no old file name?
assert.equals(0, vim.fn.filereadable(TL.default_session_path_legacy))
assert.equals(0, vim.fn.filereadable(legacy_extra_cmds_path))

assert.True(as.session_exists_for_cwd())
end)

it("can convert a session to the new format during a delete", function()
Expand Down