olimorris / persisted.nvim

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

[Bug]: Still running git commands when `use_git_branch=false` #96

Closed MasouShizuka closed 7 months ago

MasouShizuka commented 7 months ago

Your minimal.lua config

local root = "/tmp/persisted"

-- Set stdpaths to use root dir
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",
    "--single-branch",
    "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
    }
  },
  -- Put any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Error messages

No response

Describe the bug

I found that when autoload=true, neovim's startup time becomes significantly longer. image After troubleshooting, I found that this was because of the git command

As for why the startup time increased so much, it's because I'm using pwsh as the shell:

vim.opt.shell = "pwsh -NoLogo"

If comment out the above, that is, use the windows default shell: image

Then I checked the autoload function and found that if the get_branch function was changed from:

function M.get_branch()
  vim.fn.system([[git rev-parse 2> /dev/null]])
  local git_enabled = (vim.v.shell_error == 0)

  if config.options.use_git_branch and git_enabled then
    local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
...

to

function M.get_branch()
  if config.options.use_git_branch then
    vim.fn.system([[git rev-parse 2> /dev/null]])
    local git_enabled = (vim.v.shell_error == 0)
    if git_enabled then
      local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
...

Then the startup time is normal: image

Therefore, I think this code should be changed.

Reproduce the bug

No response

Final checks

olimorris commented 7 months ago

This is a great spot! And yes will defo make a difference. I'll look to merge this later today.

olimorris commented 7 months ago

@MasouShizuka this should now be fixed.