Skip to content

Commit

Permalink
feat(git): lazy now detects origin changes and will fix it on update.…
Browse files Browse the repository at this point in the history
… Fixes #346. Fixes #331
  • Loading branch information
folke committed Jan 8, 2023
1 parent a39fa0f commit 615781a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 615781a

Please sign in to comment.