Skip to content

Commit

Permalink
Merge pull request #345 from cameronr/main
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronr authored Aug 7, 2024
2 parents fe705ee + 5cd13a5 commit afa735f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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

0 comments on commit afa735f

Please sign in to comment.