Skip to content

Commit a93748a

Browse files
committed
feat(load): fallback to regular session when branch session does not exist (yet)
1 parent fc8273b commit a93748a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lua/persistence/init.lua

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ M._active = false
77

88
local e = vim.fn.fnameescape
99

10-
function M.current()
10+
---@param opts? {branch?: boolean}
11+
function M.current(opts)
12+
opts = opts or {}
1113
local name = vim.fn.getcwd():gsub("[\\/:]+", "%%")
12-
if Config.options.branch then
14+
if Config.options.branch and opts.branch ~= false then
1315
local branch = M.branch()
1416
if branch and branch ~= "main" and branch ~= "master" then
1517
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
@@ -71,7 +73,16 @@ end
7173
---@param opts? { last?: boolean }
7274
function M.load(opts)
7375
opts = opts or {}
74-
local file = opts.last and M.last() or M.current()
76+
---@type string
77+
local file
78+
if opts.last then
79+
file = M.last()
80+
else
81+
file = M.current()
82+
if vim.fn.filereadable(file) == 0 then
83+
file = M.current({ branch = false })
84+
end
85+
end
7586
if file and vim.fn.filereadable(file) ~= 0 then
7687
M.fire("LoadPre")
7788
vim.cmd("silent! source " .. e(file))

0 commit comments

Comments
 (0)