Skip to content

Commit

Permalink
fix(git): properly deal with failed clones. Fixes #571
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Feb 28, 2023
1 parent 5af9380 commit 7722378
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,24 @@ function Spec:merge(old, new)
end

function M.update_state()
---@type string[]
local cloning = {}

---@type table<string,FileType>
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
Expand Down
10 changes: 10 additions & 0 deletions lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
@@ -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<string, LazyTaskDef>
local M = {}
Expand Down Expand Up @@ -81,13 +82,22 @@ 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)
if ok then
self.plugin._.cloned = true
self.plugin._.installed = true
self.plugin._.dirty = true
vim.loop.fs_unlink(marker)
end
end,
})
Expand Down

0 comments on commit 7722378

Please sign in to comment.