From 77223786aaa91446649d0dbdc3eabc2e53f9de6d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 28 Feb 2023 11:51:16 +0100 Subject: [PATCH] fix(git): properly deal with failed clones. Fixes #571 --- lua/lazy/core/config.lua | 2 ++ lua/lazy/core/plugin.lua | 10 ++++++++++ lua/lazy/manage/task/git.lua | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index bb974f7..94f1bf0 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -188,6 +188,8 @@ function M.setup(opts) M.options.lockfile = Util.norm(M.options.lockfile) M.options.readme.root = Util.norm(M.options.readme.root) + vim.fn.mkdir(M.options.root, "p") + if M.options.performance.reset_packpath then vim.go.packpath = vim.env.VIMRUNTIME end diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index edd8ff0..f562da4 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -308,14 +308,24 @@ function Spec:merge(old, new) end function M.update_state() + ---@type string[] + local cloning = {} + ---@type table local installed = {} Util.ls(Config.options.root, function(_, name, type) if type == "directory" and name ~= "readme" then installed[name] = type + elseif type == "file" and name:sub(-8) == ".cloning" then + name = name:sub(1, -9) + cloning[#cloning + 1] = name end end) + for _, failed in ipairs(cloning) do + installed[failed] = nil + end + for _, plugin in pairs(Config.plugins) do plugin._ = plugin._ or {} if plugin.lazy == nil then diff --git a/lua/lazy/manage/task/git.lua b/lua/lazy/manage/task/git.lua index 3882362..cc1d3c4 100644 --- a/lua/lazy/manage/task/git.lua +++ b/lua/lazy/manage/task/git.lua @@ -1,6 +1,7 @@ local Git = require("lazy.manage.git") local Lock = require("lazy.manage.lock") local Config = require("lazy.core.config") +local Util = require("lazy.util") ---@type table local M = {} @@ -81,6 +82,14 @@ M.clone = { end 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", { args = args, on_exit = function(ok) @@ -88,6 +97,7 @@ M.clone = { self.plugin._.cloned = true self.plugin._.installed = true self.plugin._.dirty = true + vim.loop.fs_unlink(marker) end end, })