wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.87k stars 266 forks source link

`set_handler` triggered after plugin_type setup #992

Closed EdenEast closed 2 years ago

EdenEast commented 2 years ago

I am using set_handler to create a handler that will execute on every plugin regardless of key.

Example:

local data = {
  ["telescope.nvim"] = { commit = "6bddc38c25af7b50f99cb0c035248d7272971810", date = "2022-07-16T09:56:33+02:00"},
}
local packer = require('packer')
packer.set_handler(1, function(_, plugin, _)
  local name = plugin.short_name
  if data[name] then
    plugin.commit = data[name].commit
  end
end)
packer.init()
packer.use("nvim-telescope/telescope.nvim")

This handler does not take effect before the plugin type is setup. This means that the install_cmd does not see the commit update and sets --depth to 1 for the install command. When packer then goes to install it does see the commit change and tries to checkout the commit hash. Since the setup make the depth 1 that commit will not exist and fail to install.

There are two solutions I have thought of:

  1. Apply handlers before calling the plugin_type setup here
  2. set_handler(1, ...) might be the unintended. If so then create a similar construct for overall handler

Steps to reproduce

  1. Copy the example data and handler lines from example before your packer init/setup
  2. Delete your local telescope folder from your packer install location
  3. PackerInstall

Actual behaviour

Failed to install telescope at commit hash with a reference is not a tree.

Expected behaviour

Installed with correct commit hash

EdenEast commented 2 years ago

Closing as set_handler was not the solution to create a lockfile. Closing in favor of #1009