olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
436 stars 26 forks source link

[Bug]: Session is not stored per git branch on windows #139

Closed l3d00m closed 1 month ago

l3d00m commented 3 months ago

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

vim.opt.sessionoptions = "buffers,curdir,folds,globals,tabpages,winpos,winsize" -- Session options to store in the session

-- Install plugins
local plugins = {
    {
        "olimorris/persisted.nvim",
        opts = {
            -- Your custom config here
            use_git_branch = true,
            default_branch = "master",
            autosave = true,
        },
    },
    -- Put any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

Error messages

No error messages present

Describe the bug

With the above repro.lua nvim doesn't detect the git branch and stores all sessions only per folder, not per folder+branch. Even tho use_git_branch = true is set

This is also visible in my neovim-data/sessions directory, where there is only one session called something like C%%Users%myuser%IdeaProjects%test.vim (no other files, and no file containing the branch name)

This is on Windows! (i know, would prefer linux too). I couldn't really debug it myself since there were no error messages, is there a way to make persisted.nvim more verbose?

Reproduce the bug

  1. Starting the above repro.lua with nvim --clean -u .\repro.lua in a git repository and opening some files,
  2. then running :SessionSave
  3. Quit neovim
  4. Switch to a different branch, do the same as 1. and 2. with different files
  5. Quit neovim
  6. Return to the original branch
  7. The session from the last branch is restored, not the one from the original branch

Final checks

olimorris commented 3 months ago

Thank you for raising. Unfortunately I have no access to a Windows machine so will tag this as help wanted from the community.

l3d00m commented 3 months ago

Makes sense. Is there a way to extract any logs from persisted.nvim or make it more verbose? I'd like to debug it myself, but found it hard w/o any error messages present.

olimorris commented 3 months ago

That's a good shout. I'll add some logging tonight

olimorris commented 3 months ago

If you update the plugin and change log_level = "TRACE" that will start logging to persisted.log. The location on Mac is /Users/Oli/.local/state/nvim/persisted.log but unsure on Windows 😓 .

I may not have gone far enough with the logging so feel free to add your own. You can see from 4df3f8a that it's straightforward to do so.

l3d00m commented 3 months ago

Thanks a lot! Unfortunately I can only try this at work next Monday (since at home I don't have windows either). But this will definitely be helpful since I can also easily add my own logging statements based on this if required.

l3d00m commented 2 months ago

I could now pin it down to the usage of 2>/dev/null when running git. On windows this fails with a Path not found. This happens e.g. here: https://github.com/olimorris/persisted.nvim/blob/4df3f8a03690add1bc2f9a79b31e1c43f5e0dd05/lua/persisted/init.lua#L132

If I remove all 2>/dev/null arguments from this file (found it in 4 spots), this now works successfully under windows as well.

Maybe that already helps?

olimorris commented 2 months ago

I recall this is needed on unix based systems to discard any errors that arise from running the tool. Can we use a conditional to run a separate command for windows?

olimorris commented 2 months ago

Hey @l3d00m any update on this?

l3d00m commented 1 week ago

Sorry for never coming back to you, I had a busy time. But thanks to https://github.com/olimorris/persisted.nvim/commit/0446fd02171aeb428090d3fbb7956e849a66b9f5 it now also works on windows without problems!

olimorris commented 1 week ago

Glad to hear it!