diff options
Diffstat (limited to 'lua/lvim/bootstrap.lua')
| -rw-r--r-- | lua/lvim/bootstrap.lua | 121 | 
1 files changed, 21 insertions, 100 deletions
| diff --git a/lua/lvim/bootstrap.lua b/lua/lvim/bootstrap.lua index 702dfae1..2300c753 100644 --- a/lua/lvim/bootstrap.lua +++ b/lua/lvim/bootstrap.lua @@ -1,5 +1,13 @@  local M = {} +if vim.fn.has "nvim-0.6" ~= 1 then +  vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.6+", vim.log.levels.WARN) +  vim.wait(5000, function() +    return false +  end) +  vim.cmd "cquit" +end +  local uv = vim.loop  local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/"  local in_headless = #vim.api.nvim_list_uis() == 0 @@ -11,6 +19,16 @@ function _G.join_paths(...)    return result  end +---Require a module in protected mode without relying on its cached value +---@param module string +---@return any +function _G.require_clean(module) +  package.loaded[module] = nil +  _G[module] = nil +  local _, requested = pcall(require, module) +  return requested +end +  ---Get the full path to `$LUNARVIM_RUNTIME_DIR`  ---@return string  function _G.get_runtime_dir() @@ -96,106 +114,9 @@ end  ---Update LunarVim  ---pulls the latest changes from github and, resets the startup cache  function M:update() -  package.loaded["lvim.utils.hooks"] = nil -  local _, hooks = pcall(require, "lvim.utils.hooks") -  hooks.run_pre_update() -  M:update_repo() -  hooks.run_post_update() -end - -local function git_cmd(subcmd, opts) -  local Job = require "plenary.job" -  local Log = require "lvim.core.log" -  local args = { "-C", opts.cwd } -  vim.list_extend(args, subcmd) - -  local stderr = {} -  local stdout, ret = Job -    :new({ -      command = "git", -      args = args, -      cwd = opts.cwd, -      on_stderr = function(_, data) -        table.insert(stderr, data) -      end, -    }) -    :sync() - -  if not vim.tbl_isempty(stderr) then -    Log:debug(stderr) -  end - -  if not vim.tbl_isempty(stdout) then -    Log:debug(stdout) -  end - -  return ret, stdout -end - ----pulls the latest changes from github -function M:update_repo() -  local Log = require "lvim.core.log" -  local sub_commands = { -    fetch = { "fetch" }, -    diff = { "diff", "--quiet", "@{upstream}" }, -    merge = { "merge", "--ff-only", "--progress" }, -  } -  local opts = { -    cwd = get_lvim_base_dir(), -  } -  Log:info "Checking for updates" - -  local ret = git_cmd(sub_commands.fetch, opts) -  if ret ~= 0 then -    Log:error "Update failed! Check the log for further information" -    return -  end - -  ret = git_cmd(sub_commands.diff, opts) - -  if ret == 0 then -    Log:info "LunarVim is already up-to-date" -    return -  end - -  ret = git_cmd(sub_commands.merge, opts) - -  if ret ~= 0 then -    Log:error "Update failed! Please pull the changes manually instead." -    return -  end -end - ----Get currently installed version of LunarVim ----@param type string can be "short" ----@return string -function M:get_version(type) -  type = type or "" -  local opts = { cwd = get_lvim_base_dir() } - -  local _, branch = git_cmd({ "branch", "--show-current" }, opts) - -  local is_on_master = branch == "master" -  if not is_on_master then -    local log_status_ok, log_results = git_cmd({ "log", "--pretty=format:%h", "-1" }, opts) -    local abbrev_version = log_results[1] or "" -    if not log_status_ok or string.match(abbrev_version, "%d") == nil then -      return nil -    end -    return "dev-" .. abbrev_version -  end - -  local tag_status_ok, results = git_cmd({ "describe", "--tags" }, opts) -  local lvim_full_ver = results[1] or "" - -  if not tag_status_ok or string.match(lvim_full_ver, "%d") == nil then -    return nil -  end -  if type == "short" then -    return vim.fn.split(lvim_full_ver, "-")[1] -  else -    return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1) -  end +  require_clean("lvim.utils.hooks").run_pre_update() +  require_clean("lvim.utils.git").update_base_lvim() +  require_clean("lvim.utils.hooks").run_post_update()  end  return M | 
