mirror of https://github.com/folke/lazy.nvim.git
feat(restore): you can now restore a plugin to a certain commit. Fixes #234
This commit is contained in:
parent
4b29f7e3d5
commit
1283c2b288
30
README.md
30
README.md
|
@ -483,21 +483,21 @@ Any operation can be started from the UI, with a sub command or an API function:
|
||||||
|
|
||||||
<!-- commands:start -->
|
<!-- commands:start -->
|
||||||
|
|
||||||
| Command | Lua | Description |
|
| Command | Lua | Description |
|
||||||
| ------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------- |
|
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
|
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
|
||||||
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
|
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
|
||||||
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
|
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
|
||||||
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
|
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
|
||||||
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
|
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
|
||||||
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
|
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
|
||||||
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
|
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
|
||||||
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim` |
|
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim` |
|
||||||
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
|
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
|
||||||
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
|
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
|
||||||
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile |
|
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
|
||||||
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
|
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
|
||||||
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
|
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
|
||||||
|
|
||||||
<!-- commands:end -->
|
<!-- commands:end -->
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,8 @@ M.commands = {
|
||||||
},
|
},
|
||||||
restore = {
|
restore = {
|
||||||
button = true,
|
button = true,
|
||||||
desc = "Updates all plugins to the state in the lockfile",
|
desc = "Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor",
|
||||||
desc_plugin = "Restore a plugin to the state in the lockfile",
|
desc_plugin = "Restore a plugin to the state in the lockfile or to a given commit under the cursor",
|
||||||
id = 8,
|
id = 8,
|
||||||
key = "R",
|
key = "R",
|
||||||
key_plugin = "r",
|
key_plugin = "r",
|
||||||
|
|
|
@ -164,6 +164,25 @@ function M:setup_patterns()
|
||||||
self:diff({ commit = hash })
|
self:diff({ commit = hash })
|
||||||
end,
|
end,
|
||||||
}, self.diff)
|
}, self.diff)
|
||||||
|
self:on_pattern(ViewConfig.commands.restore.key_plugin, {
|
||||||
|
[commit_pattern] = function(hash)
|
||||||
|
self:restore({ commit = hash })
|
||||||
|
end,
|
||||||
|
}, self.restore)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param opts? {commit:string}
|
||||||
|
function M:restore(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local Lockfile = require("lazy.manage.lock")
|
||||||
|
local Commands = require("lazy.view.commands")
|
||||||
|
local plugin = self.render:get_plugin()
|
||||||
|
if plugin then
|
||||||
|
if opts.commit then
|
||||||
|
Lockfile.get(plugin).commit = opts.commit
|
||||||
|
end
|
||||||
|
Commands.cmd("restore", { plugins = { plugin } })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:hover()
|
function M:hover()
|
||||||
|
@ -246,7 +265,7 @@ function M:setup_modes()
|
||||||
Commands.cmd(name)
|
Commands.cmd(name)
|
||||||
end, m.desc)
|
end, m.desc)
|
||||||
end
|
end
|
||||||
if m.key_plugin then
|
if m.key_plugin and name ~= "restore" then
|
||||||
self:on_key(m.key_plugin, function()
|
self:on_key(m.key_plugin, function()
|
||||||
local plugin = self.render:get_plugin()
|
local plugin = self.render:get_plugin()
|
||||||
if plugin then
|
if plugin then
|
||||||
|
|
Loading…
Reference in New Issue