feat(git): lazy now detects origin changes and will fix it on update. Fixes #346. Fixes #331

This commit is contained in:
Folke Lemaitre 2023-01-08 08:32:03 +01:00
parent a39fa0f0ce
commit 615781aebf
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 30 additions and 1 deletions

View file

@ -113,6 +113,30 @@ M.branch = {
end,
}
-- check and switch origin
M.origin = {
skip = function(plugin)
if not plugin._.installed or plugin._.is_local then
return true
end
local origin = Git.get_origin(plugin.dir)
return origin == plugin.url
end,
---@param opts {check?:boolean}
run = function(self, opts)
if opts.check then
local origin = Git.get_origin(self.plugin.dir)
self.error = "Origin has changed:\n"
self.error = self.error .. " * old: " .. origin .. "\n"
self.error = self.error .. " * new: " .. self.plugin.url .. "\n"
self.error = self.error .. "Please run update to fix"
return
end
require("lazy.manage.task.fs").clean.run(self, opts)
M.clone.run(self, opts)
end,
}
-- fetches all needed origin branches
M.fetch = {
skip = function(plugin)