You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Objective: Open Neovim in a git repository on a feature branch and on exit save the session for that specific feature branch.
Expected Behavior: On exit, a session file is generated with the correct branch name appended.
Actual Behavior: A session file is generated with the default branch name, in my case 'main'.
Running 'SaveSession' gives us a clue about what's going on. It's complaining that it could not load a session for branch "my_feature_branch". This doesn't make sense as of course there is no branch to load, we are trying to create one by saving. The issue is under get_branch() it is checking if a session already exists for that branch and fails. I removed the check for filereadable and just returned branch to get it to work the way I expect it to.
I'm not sure what the original purpose of writing this way was, but I'm sure it has a good reason to be there. Otherwise, works great, thanks for making this plugin!
---Get the current Git branch---@paramdir?string Directory to be used for the session---@returnstring|nilfunctionM.get_branch(dir)
dir=dirorsession_dir()
ifconfig.options.use_git_branchthenvim.fn.system('git -C "' ..dir..'" rev-parse 2>/dev/null')
localgit_enabled= (vim.v.shell_error==0)
ifgit_enabledthenlocalgit_branch=vim.fn.systemlist('git -C "' ..dir..'" rev-parse --abbrev-ref HEAD 2>/dev/null')
ifvim.v.shell_error==0thenlocalbranch=config.options.branch_separator..git_branch[1]:gsub("/", "%%")
localbranch_session=config.options.save_dir..dir:gsub(utils.get_dir_pattern(), "%%") ..branch..".vim"-- Try to load the session for the current branchifvim.fn.filereadable(branch_session) ~=0thenreturnbranchelsevim.notify(
string.format("[Persisted.nvim]: Trying to load a session for branch %s", config.options.default_branch),
vim.log.levels.INFO
)
vim.notify(
string.format("[Persisted.nvim]: Could not load a session for branch %s.", git_branch[1]),
vim.log.levels.WARN
)
vim.g.persisted_branch_session=branch_sessionreturnconfig.options.branch_separator..config.options.default_branchendendendendend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Objective: Open Neovim in a git repository on a feature branch and on exit save the session for that specific feature branch.
Expected Behavior: On exit, a session file is generated with the correct branch name appended.
Actual Behavior: A session file is generated with the default branch name, in my case 'main'.
Running 'SaveSession' gives us a clue about what's going on. It's complaining that it could not load a session for branch "my_feature_branch". This doesn't make sense as of course there is no branch to load, we are trying to create one by saving. The issue is under
get_branch()
it is checking if a session already exists for that branch and fails. I removed the check forfilereadable
and just returned branch to get it to work the way I expect it to.I'm not sure what the original purpose of writing this way was, but I'm sure it has a good reason to be there. Otherwise, works great, thanks for making this plugin!
Beta Was this translation helpful? Give feedback.
All reactions