From c18ee3cd1b4157b14b87f7d935975f72829f1577 Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Sun, 3 Sep 2023 23:41:31 +0200 Subject: [PATCH] Make sure lazy setup is using the locked commit --- init.lua | 22 +------------------ lua/valeth/lazy.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 lua/valeth/lazy.lua diff --git a/init.lua b/init.lua index 380eebf..b3077ab 100644 --- a/init.lua +++ b/init.lua @@ -1,23 +1,3 @@ require("valeth.options") require("valeth.keymaps") - -local function lazy_setup() - local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" - - if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) - end - - vim.opt.rtp:prepend(lazypath) - - require("lazy").setup("valeth.plugins") -end - -lazy_setup() +require("valeth.lazy") diff --git a/lua/valeth/lazy.lua b/lua/valeth/lazy.lua new file mode 100644 index 0000000..52fce86 --- /dev/null +++ b/lua/valeth/lazy.lua @@ -0,0 +1,53 @@ +local uv = vim.loop + + +local function locked_commit() + local lockfile_path = vim.fn.stdpath("config") .. "/lazy-lock.json" + local lockfile = io.open(lockfile_path, "r") + + if not lockfile then + return nil + end + + local text = lockfile:read("*all") + lockfile:close() + local json = vim.json.decode(text) + + return json["lazy.nvim"]["commit"] +end + + +local function checkout_commit(path) + local commit = locked_commit() + + if not commit then + return + end + + uv.spawn("git", { + args = { "checkout", commit }, + cwd = path + }) +end + + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) + + checkout_commit(lazypath) + vim.wait(1) + vim.notify("Installed lazy.nvim") +end + +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup("valeth.plugins")