Browse Source

feat: lock nvim <0.7 to a specific tag (#2491)

kylo252 3 years ago
parent
commit
3d841425ae
3 changed files with 34 additions and 5 deletions
  1. 6 4
      lua/lvim/bootstrap.lua
  2. 11 1
      lua/lvim/utils/git.lua
  3. 17 0
      lua/lvim/utils/hooks.lua

+ 6 - 4
lua/lvim/bootstrap.lua

@@ -1,7 +1,7 @@
 local M = {}
 
-if vim.fn.has "nvim-0.6.1" ~= 1 then
-  vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.6.1+", vim.log.levels.WARN)
+if vim.fn.has "nvim-0.7" ~= 1 then
+  vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.7+", vim.log.levels.WARN)
   vim.wait(5000, function()
     return false
   end)
@@ -115,8 +115,10 @@ end
 ---pulls the latest changes from github and, resets the startup cache
 function M:update()
   require_clean("lvim.utils.hooks").run_pre_update()
-  require_clean("lvim.utils.git").update_base_lvim()
-  require_clean("lvim.utils.hooks").run_post_update()
+  local ret = require_clean("lvim.utils.git").update_base_lvim()
+  if ret then
+    require_clean("lvim.utils.hooks").run_post_update()
+  end
 end
 
 return M

+ 11 - 1
lua/lvim/utils/git.lua

@@ -72,6 +72,8 @@ function M.update_base_lvim()
     Log:error "Update failed! Please pull the changes manually instead."
     return
   end
+
+  return true
 end
 
 ---Switch Lunarvim to the specified development branch
@@ -80,11 +82,19 @@ function M.switch_lvim_branch(branch)
   if not safe_deep_fetch() then
     return
   end
-  local ret = git_cmd { args = { "switch", branch } }
+  local args = { "switch", branch }
+
+  if branch:match "^[0-9]" then
+    -- avoids producing an error for tags
+    vim.list_extend(args, { "--detach" })
+  end
+
+  local ret = git_cmd { args = args }
   if ret ~= 0 then
     Log:error "Unable to switch branches! Check the log for further information"
     return
   end
+  return true
 end
 
 ---Get the current Lunarvim development branch

+ 17 - 0
lua/lvim/utils/hooks.lua

@@ -51,6 +51,23 @@ end
 
 function M.run_post_update()
   Log:debug "Starting post-update hook"
+
+  if vim.fn.has "nvim-0.7" ~= 1 then
+    local compat_tag = "1.1.3"
+    vim.notify(
+      "Please upgrade your Neovim base installation. Newer version of Lunarvim requires v0.7+",
+      vim.log.levels.WARN
+    )
+    vim.wait(1000, function()
+      return false
+    end)
+    local ret = require_clean("lvim.utils.git").switch_lvim_branch(compat_tag)
+    if ret then
+      vim.notify("Reverted to the last known compatibile version: " .. compat_tag, vim.log.levels.WARN)
+    end
+    return
+  end
+
   M.reset_cache()
 
   Log:debug "Syncing core plugins"