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

@ -94,6 +94,7 @@ function M.update(opts)
opts = M.opts(opts, { mode = "update" })
return M.run({
pipeline = {
"git.origin",
"git.branch",
"git.fetch",
{ "git.checkout", lockfile = opts.lockfile },
@ -123,6 +124,7 @@ function M.check(opts)
opts = opts or {}
return M.run({
pipeline = {
{ "git.origin", check = true },
"git.fetch",
"wait",
{ "git.log", check = true },
@ -137,7 +139,10 @@ end
function M.log(opts)
opts = M.opts(opts, { mode = "log" })
return M.run({
pipeline = { "git.log" },
pipeline = {
{ "git.origin", check = true },
"git.log",
},
plugins = function(plugin)
return plugin.url and plugin._.installed
end,

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)