fix(git): properly deal with failed clones. Fixes #571

This commit is contained in:
Folke Lemaitre 2023-02-28 11:51:16 +01:00
parent 5af93806aa
commit 77223786aa
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 22 additions and 0 deletions

View File

@ -188,6 +188,8 @@ function M.setup(opts)
M.options.lockfile = Util.norm(M.options.lockfile) M.options.lockfile = Util.norm(M.options.lockfile)
M.options.readme.root = Util.norm(M.options.readme.root) M.options.readme.root = Util.norm(M.options.readme.root)
vim.fn.mkdir(M.options.root, "p")
if M.options.performance.reset_packpath then if M.options.performance.reset_packpath then
vim.go.packpath = vim.env.VIMRUNTIME vim.go.packpath = vim.env.VIMRUNTIME
end end

View File

@ -308,14 +308,24 @@ function Spec:merge(old, new)
end end
function M.update_state() function M.update_state()
---@type string[]
local cloning = {}
---@type table<string,FileType> ---@type table<string,FileType>
local installed = {} local installed = {}
Util.ls(Config.options.root, function(_, name, type) Util.ls(Config.options.root, function(_, name, type)
if type == "directory" and name ~= "readme" then if type == "directory" and name ~= "readme" then
installed[name] = type installed[name] = type
elseif type == "file" and name:sub(-8) == ".cloning" then
name = name:sub(1, -9)
cloning[#cloning + 1] = name
end end
end) end)
for _, failed in ipairs(cloning) do
installed[failed] = nil
end
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
plugin._ = plugin._ or {} plugin._ = plugin._ or {}
if plugin.lazy == nil then if plugin.lazy == nil then

View File

@ -1,6 +1,7 @@
local Git = require("lazy.manage.git") local Git = require("lazy.manage.git")
local Lock = require("lazy.manage.lock") local Lock = require("lazy.manage.lock")
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Util = require("lazy.util")
---@type table<string, LazyTaskDef> ---@type table<string, LazyTaskDef>
local M = {} local M = {}
@ -81,6 +82,14 @@ M.clone = {
end end
table.insert(args, self.plugin.dir) table.insert(args, self.plugin.dir)
if vim.fn.isdirectory(self.plugin.dir) == 1 then
require("lazy.manage.task.fs").clean.run(self, {})
end
local marker = self.plugin.dir .. ".cloning"
Util.write_file(marker, "")
self:spawn("git", { self:spawn("git", {
args = args, args = args,
on_exit = function(ok) on_exit = function(ok)
@ -88,6 +97,7 @@ M.clone = {
self.plugin._.cloned = true self.plugin._.cloned = true
self.plugin._.installed = true self.plugin._.installed = true
self.plugin._.dirty = true self.plugin._.dirty = true
vim.loop.fs_unlink(marker)
end end
end, end,
}) })