Skip to content

Commit 7722378

Browse files
committed
fix(git): properly deal with failed clones. Fixes #571
1 parent 5af9380 commit 7722378

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lua/lazy/core/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ function M.setup(opts)
188188
M.options.lockfile = Util.norm(M.options.lockfile)
189189
M.options.readme.root = Util.norm(M.options.readme.root)
190190

191+
vim.fn.mkdir(M.options.root, "p")
192+
191193
if M.options.performance.reset_packpath then
192194
vim.go.packpath = vim.env.VIMRUNTIME
193195
end

lua/lazy/core/plugin.lua

+10
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,24 @@ function Spec:merge(old, new)
308308
end
309309

310310
function M.update_state()
311+
---@type string[]
312+
local cloning = {}
313+
311314
---@type table<string,FileType>
312315
local installed = {}
313316
Util.ls(Config.options.root, function(_, name, type)
314317
if type == "directory" and name ~= "readme" then
315318
installed[name] = type
319+
elseif type == "file" and name:sub(-8) == ".cloning" then
320+
name = name:sub(1, -9)
321+
cloning[#cloning + 1] = name
316322
end
317323
end)
318324

325+
for _, failed in ipairs(cloning) do
326+
installed[failed] = nil
327+
end
328+
319329
for _, plugin in pairs(Config.plugins) do
320330
plugin._ = plugin._ or {}
321331
if plugin.lazy == nil then

lua/lazy/manage/task/git.lua

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local Git = require("lazy.manage.git")
22
local Lock = require("lazy.manage.lock")
33
local Config = require("lazy.core.config")
4+
local Util = require("lazy.util")
45

56
---@type table<string, LazyTaskDef>
67
local M = {}
@@ -81,13 +82,22 @@ M.clone = {
8182
end
8283

8384
table.insert(args, self.plugin.dir)
85+
86+
if vim.fn.isdirectory(self.plugin.dir) == 1 then
87+
require("lazy.manage.task.fs").clean.run(self, {})
88+
end
89+
90+
local marker = self.plugin.dir .. ".cloning"
91+
Util.write_file(marker, "")
92+
8493
self:spawn("git", {
8594
args = args,
8695
on_exit = function(ok)
8796
if ok then
8897
self.plugin._.cloned = true
8998
self.plugin._.installed = true
9099
self.plugin._.dirty = true
100+
vim.loop.fs_unlink(marker)
91101
end
92102
end,
93103
})

0 commit comments

Comments
 (0)