فهرست منبع

refactor(installer): skip unstable headless update (#3338)

kylo252 2 سال پیش
والد
کامیت
74ad56ff68
4فایلهای تغییر یافته به همراه41 افزوده شده و 47 حذف شده
  1. 1 3
      lua/lvim/core/log.lua
  2. 3 4
      lua/lvim/plugin-loader.lua
  3. 15 0
      utils/ci/verify_plugins.lua
  4. 22 40
      utils/installer/install.sh

+ 1 - 3
lua/lvim/core/log.lua

@@ -20,8 +20,6 @@ function Log:set_level(level)
     for _, s in ipairs(logger.sinks) do
       s.level = log_level
     end
-  else
-    vim.notify_once("Unable to set logger's level to " .. level)
   end
 
   local packer_ok, _ = xpcall(function()
@@ -87,7 +85,7 @@ function Log:init()
         -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5
         vim_log_level = vim_log_level + 1
       end
-      
+
       self:add_entry(vim_log_level, msg)
     end
   end

+ 3 - 4
lua/lvim/plugin-loader.lua

@@ -42,11 +42,10 @@ function plugin_loader.init(opts)
   end
 
   if not utils.is_directory(install_path) then
-    vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
+    print "Initializing first time setup"
+    print "Installing packer"
+    print(vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
     vim.cmd "packadd packer.nvim"
-    -- IMPORTANT: we only set this the very first time to avoid constantly triggering the rollback function
-    -- https://github.com/wbthomason/packer.nvim/blob/c576ab3f1488ee86d60fd340d01ade08dcabd256/lua/packer.lua#L998-L995
-    init_opts.snapshot = default_snapshot
   end
 
   local status_ok, packer = pcall(require, "packer")

+ 15 - 0
utils/ci/verify_plugins.lua

@@ -26,6 +26,20 @@ end
 local is_directory = require("lvim.utils").is_directory
 -- see packer.init()
 local packdir = join_paths(get_runtime_dir(), "site", "pack", "packer")
+
+local verify_packer = function()
+  if not is_directory(packdir) then
+    io.write "Packer not installed!"
+    os.exit(1)
+  end
+  local status_ok, packer = pcall(require, "packer")
+  if status_ok and packer then
+    return
+  end
+  io.write "Packer not installed!"
+  os.exit(1)
+end
+
 local packer_config = { opt_dir = join_paths(packdir, "opt"), start_dir = join_paths(packdir, "start") }
 local is_optional = function(spec)
   return spec.opt or spec.event or spec.cmd or spec.module
@@ -130,5 +144,6 @@ local function verify_core_plugins(verbose)
   end)
 end
 
+verify_packer()
 verify_core_plugins()
 vim.cmd "q"

+ 22 - 40
utils/installer/install.sh

@@ -1,6 +1,8 @@
 #!/usr/bin/env bash
 set -eo pipefail
 
+OS="$(uname -s)"
+
 #Set branch to master unless specified by the user
 declare -x LV_BRANCH="${LV_BRANCH:-"master"}"
 declare -xr LV_REMOTE="${LV_REMOTE:-lunarvim/lunarvim.git}"
@@ -32,6 +34,7 @@ declare -a __lvim_dirs=(
   "$LUNARVIM_CONFIG_DIR"
   "$LUNARVIM_RUNTIME_DIR"
   "$LUNARVIM_CACHE_DIR"
+  "$LUNARVIM_BASE_DIR"
 )
 
 declare -a __npm_deps=(
@@ -135,14 +138,12 @@ function main() {
     fi
   fi
 
-  backup_old_config
+  remove_old_cache_files
 
   verify_lvim_dirs
 
   if [ "$ARGS_LOCAL" -eq 1 ]; then
     link_local_lvim
-  elif [ -d "$LUNARVIM_BASE_DIR" ]; then
-    validate_lunarvim_files
   else
     clone_lvim
   fi
@@ -156,7 +157,6 @@ function main() {
 }
 
 function detect_platform() {
-  OS="$(uname -s)"
   case "$OS" in
     Linux)
       if [ -f "/etc/arch-release" ] || [ -f "/etc/artix-release" ]; then
@@ -219,15 +219,6 @@ function verify_core_plugins() {
   echo "Verification complete!"
 }
 
-function validate_lunarvim_files() {
-  local verify_version_cmd='if v:errmsg != "" | cquit | else | quit | endif'
-  if ! "$INSTALL_PREFIX/bin/lvim" --headless -c 'LvimUpdate' -c "$verify_version_cmd" &>/dev/null; then
-    msg "Removing old installation files"
-    rm -rf "$LUNARVIM_BASE_DIR"
-    clone_lvim
-  fi
-}
-
 function validate_install_prefix() {
   local prefix="$1"
   case $PATH in
@@ -353,43 +344,37 @@ function install_rust_deps() {
   echo "All Rust dependencies are successfully installed"
 }
 
-function verify_lvim_dirs() {
-  if [ "$ARGS_OVERWRITE" -eq 1 ]; then
-    for dir in "${__lvim_dirs[@]}"; do
-      [ -d "$dir" ] && rm -rf "$dir"
-    done
-  fi
-
-  for dir in "${__lvim_dirs[@]}"; do
-    mkdir -p "$dir"
-  done
-}
-
-function backup_old_config() {
-  local src="$LUNARVIM_CONFIG_DIR"
+function __backup_dir() {
+  local src="$1"
   if [ ! -d "$src" ]; then
     return
   fi
   mkdir -p "$src.old"
-  touch "$src/ignore"
   msg "Backing up old $src to $src.old"
   if command -v rsync &>/dev/null; then
-    rsync --archive -hh --stats --partial --copy-links --cvs-exclude "$src"/ "$src.old"
+    rsync --archive --quiet --backup --partial --copy-links --cvs-exclude "$src"/ "$src.old"
   else
-    OS="$(uname -s)"
     case "$OS" in
-      Linux | *BSD)
-        cp -r "$src/"* "$src.old/."
-        ;;
       Darwin)
         cp -R "$src/"* "$src.old/."
         ;;
       *)
-        echo "OS $OS is not currently supported."
+        cp -r "$src/"* "$src.old/."
         ;;
     esac
   fi
-  msg "Backup operation complete"
+}
+
+function verify_lvim_dirs() {
+  for dir in "${__lvim_dirs[@]}"; do
+    if [ -d "$dir" ]; then
+      if [ "$ARGS_OVERWRITE" -eq 0 ]; then
+        __backup_dir "$dir"
+      fi
+      rm -rf "$dir"
+    fi
+    mkdir -p "$dir"
+  done
 }
 
 function clone_lvim() {
@@ -406,8 +391,8 @@ function link_local_lvim() {
 
   # Detect whether it's a symlink or a folder
   if [ -d "$LUNARVIM_BASE_DIR" ]; then
-    echo "Removing old installation files"
-    rm -rf "$LUNARVIM_BASE_DIR"
+    msg "Moving old files to ${LUNARVIM_BASE_DIR}.old"
+    mv "$LUNARVIM_BASE_DIR" "${LUNARVIM_BASE_DIR}".old
   fi
 
   echo "   - $BASEDIR -> $LUNARVIM_BASE_DIR"
@@ -433,8 +418,6 @@ function remove_old_cache_files() {
 
 function setup_lvim() {
 
-  remove_old_cache_files
-
   msg "Installing LunarVim shim"
 
   setup_shim
@@ -456,7 +439,6 @@ function setup_lvim() {
 }
 
 function create_desktop_file() {
-  OS="$(uname -s)"
   # TODO: Any other OSes that use desktop files?
   ([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return
   echo "Creating desktop file"